Skip to content

Commit 08f3398

Browse files
committed
Take care of ints in the YAML file in a cleaner way
1 parent 588fa4f commit 08f3398

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

update_tests.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44
import sys
55
from navigation import SolusSession
66

7+
def str_unless_none(obj):
8+
"""Convert an object to a string unless it's None"""
9+
if obj is not None:
10+
return str(obj)
11+
return obj
12+
713
def iterkeyvalue(obj):
814
"""Make it easy to iterate over dicts, lists, and strings"""
915
if isinstance(obj, dict):
1016
for k, v in obj.items():
11-
yield k, v
17+
yield str_unless_none(k), v
1218
elif isinstance (obj, list):
1319
for x in obj:
14-
yield x, None
20+
yield str_unless_none(x), None
1521
else:
16-
yield obj, None
22+
yield str_unless_none(obj), None
1723

1824
def get_filter(obj):
1925
"""Pick out the list of objects to filter by from a config item"""
20-
# TODO: Fix str mapping once when parsing the config file
2126
if obj is None:
2227
return [] # Empty list = accept nothing (optimized in the parser)
2328
elif hasattr(obj, "keys"):
@@ -110,7 +115,6 @@ def scrape_courses(self, courses):
110115

111116
# Iterate over all courses
112117
for course, terms in iterkeyvalue(courses):
113-
course = str(course) if course is not None else None # TODO: Fix once when parsing the config file
114118

115119
curr_course = all_courses.get(course)
116120
if curr_course is None:
@@ -158,7 +162,6 @@ def scrape_sections(self, sections):
158162
# Don't really need the `iterkeyvalue` but it makes the config
159163
# parsing a litte more lax so whatever
160164
for section, _ in iterkeyvalue(sections):
161-
section = str(section) if section is not None else None #TODO: ugh
162165

163166
curr_section = all_sections.get(section)
164167
if curr_section is None:

0 commit comments

Comments
 (0)