fix: rewrite course string parser#90
Conversation
| pylint = "*" | ||
| colorama = "*" | ||
| snapshottest = "*" | ||
| click = "*" |
There was a problem hiding this comment.
Was already used by flask
| print(e.message, '-', e.details) | ||
|
|
||
|
|
||
| class TestParseCourseString(TestCase): |
| if len(without_dept) < 6 or len(without_dept) > 8: | ||
| raise ValidationError( | ||
| f"Invalid course + section string ('{without_dept}')", | ||
| 'Length is not between 6-8 chars' |
There was a problem hiding this comment.
Why does length have to be between 6-8 chars?
There was a problem hiding this comment.
Are there valid cases more or less than that count?
There was a problem hiding this comment.
The fundamental assumptions that are made throughout this parser are as follows:
F 1AHL 01Z
First char - campus
Next four char - course (may start with 0's and/or end with .)
All chars afterwards - section (max 3 chars)
Therefore, the string needs to be at least 6 chars and no more than 8 chars. In practice, all course strings are between 7-8 chars.
| section = without_dept[5:] | ||
|
|
||
| # Extract flags by filtering nonalphabets from the class section string | ||
| flags = set(filter(str.isalpha, section)) |
There was a problem hiding this comment.
this is a filter to get rid of .?
There was a problem hiding this comment.
No, that is done through the regex. This chooses alphabets from the section string (ex. 1HZ => {'H', 'Z'}).
|
|
||
| # The last chars are the class section + flags | ||
| # ex. `01Z` or `5ZH` | ||
| section = without_dept[5:] |
There was a problem hiding this comment.
Are we storing variant from section?
phi-line
left a comment
There was a problem hiding this comment.
looks good! thanks for PR
- Document methodology for parsing course string - More tests - Minor changes
Fixes #75.