Script to test index.html for validity #341
Conversation
7. instructor list should be a valid Python/Ruby list | ||
''' | ||
|
||
import sys as _sys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the first time that I see this.
If you have plans to use a variable named sys
you should use sys_
following PEP8:
single_trailing_underscore_
: used by convention to avoid conflicts with Python keyword
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good that you're as confused about this as I am!
setup/swc-installation-test1.py
and setup/swc-installation-test2.py
do this, so I thought this was some kind of internal standard that I knew nothing about, so I copied it: cargo-cult programming. Will delete this in the next commit.
@DrSnuggles, Thanks for the contribution. =) |
…eaks up some more long lines.
Cool! Check the newest commit, I put in all of your comments except that I left the check for countries like it is (for now?). The script also now checks for that template header and warns the user if it still exists. Edit: Also, currently the script assumes that there is a email address, but the Jekyll code in index.html puts in the site's contact if the email address isn't specified. Is that behavior still wanted? Then I'd have to change the categories rule a bit. |
filename = args[1] | ||
|
||
sys.stderr.write('Testing file "%s".\n' %filename) | ||
index_fh = open(filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to close the file. What about use with
?
@DrSnuggles Thanks for all the help with this script. Could you add the check function for all the categories, including
Nice.
|
I think that I now got all categories, and it now uses the "with" operator. If someone could test this under Windows I'd be grateful - so far only tested on Fedora 19, python 2.7.5 and 3.3.2 |
@DrSnuggles Sorry for the delay to do another review round.
|
Hi, thanks for the comments! No worries about the tiny delay, I'm a bit busy right now anyway. I'll implement the suggestions, pyYAML is a way better idea since then we wouldn't have to worry about white-spaces etc. if you want to write tests, go ahead :) |
OK, done! I'm now using |
- Add unit test to all check functions - Add unit test to file handler Changes in swc_index_validator.py - Remove some calls to `strip()` They aren't necessary any more because we use PyYAML. - Changes in `check_contry()` Use only one conditional - Change in `check_intructor()` Check if the list isn't empty. TODO: - Fix the unit test that fail.
@DrSnuggles I just send you a PR with the unit tests. There is two last thing that I would like before accept this PR:
|
Add unit tests
Cool, thank you! I've introduced extra-checks to fix the tests (humandate's year has to be all-numbers, humandate's day has to contain some numbers, humantime has to contain some numbers), and I fixed a minor issue with the test's StringIO behaving differently under Python2, now it should work under both 2 and 3 (at least it does on my Fedora). By the new string formatting method, do you mean to replace all instances of
by
? |
@DrSnuggles The answer to your question is YES. Sorry for the delay to reply your question. The email notification send by GitHub don't have your question. (Did you edit/update your last comment? I would like to discovery why this happen to avoid it happen again.) And thanks to make it work with Python2. |
|
||
def check_layout(layout): | ||
'''Checks whether layout equals "bootcamp".''' | ||
if layout != 'bootcamp': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return layout == 'bootcamp'
|
||
def check_humantime(time): | ||
'''A valid humantime contains at least one number''' | ||
return bool(re.match(HUMANTIME_PATTERN, time.replace(" ",""))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the bool
conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is (I think) that the AND operator I use on the returned function expects a boolean variable:
TypeError: unsupported operand type(s) for &=: 'bool' and '_sre.SRE_Match'
I could wrap the re.match into an if-statement, but that is a bit ugly:
if re.match(re.match(HUMANTIME_PATTERN, time.replace(" ","")):
return True
return False
So I thought that the bool-conversion is the "laziest" and nicest way.. could I make it nicer?
Script to test index.html for validity
Script to test index.html for validity
For issue #320
This is by no means exhaustive but I think a good start.