forked from adfinis/flappy-sez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lines.py
executable file
·30 lines (25 loc) · 920 Bytes
/
test_lines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3
import sys
import string
import textwrap
DATE_PLACEHOLDER = "XXX DD.MM."
ALLOWED_CHARACTERS = set(string.ascii_letters + string.digits + " " + "." + "/" + "-")
fails = False
with open(sys.argv[1], "r") as fh:
for i, line in enumerate(fh.read().splitlines()):
# Check for invalid characters
if not set(line).issubset(ALLOWED_CHARACTERS):
fails = True
print("Line %i contains invalid characters: %s" % (i + 1, line))
# Check for wordwrapping
text = "%s %s" % (DATE_PLACEHOLDER, line)
lines = textwrap.wrap(text, 26)
if len(lines) > 2:
fails = True
print("Line %i too long: %s" % (i + 1, line))
if any(len(l) > 26 for l in lines):
print("Line %i cannot be word-wrapped: %s" % (i + 1, line))
if fails:
sys.exit(1)
else:
print("All lines look OK and should fit on flappy")