Added assertions to make sure csv data is correctly formatted (fixes #8)
This commit is contained in:
parent
f43c94c626
commit
263bcf0870
1 changed files with 8 additions and 0 deletions
|
@ -53,6 +53,14 @@ for root, dirs, files in os.walk('quotes/'):
|
|||
csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='`', skipinitialspace=True)
|
||||
quotes += list(csvreader)
|
||||
|
||||
for q in quotes:
|
||||
# Check correct number of fields
|
||||
assert (len(q) == 4), "Error: wrong number of fields in " + str(q)
|
||||
# Check correct field names
|
||||
assert ('quote' in q and 'author' in q and 'link' in q and 'linktitle' in q), "Error: missing field in " + str(q)
|
||||
# Check that no field is empty
|
||||
assert (q['quote'] and q['author'] and q['link'] and q['linktitle']), "Error: empty field in " + str(q)
|
||||
|
||||
print(f"Found {len(quotes)} total quotes")
|
||||
|
||||
row = random.choice(quotes)
|
||||
|
|
Loading…
Reference in a new issue