Tests on Windows, better exception handling

This commit is contained in:
2023-03-08 19:07:39 +01:00
parent 39912002f2
commit 8bf49e052a
5 changed files with 105 additions and 44 deletions

View File

@@ -1,5 +1,6 @@
import unittest
import subprocess
import platform
class TestCommandLine(unittest.TestCase):
@@ -12,20 +13,30 @@ class TestCommandLine(unittest.TestCase):
is_help_line = False
for line in readme.readlines():
if line == "> dyn2py --help":
line_text = line.rstrip()
if line_text == "> dyn2py --help":
is_help_line = True
elif is_help_line and line == "```":
elif is_help_line and line_text == "```":
# It's the end of the help
break
elif is_help_line:
readme_help_lines.append(line)
readme_help_lines.append(line_text)
for arg in args:
p = subprocess.run(
["dyn2py", arg], capture_output=True, shell=True)
output_help = p.stdout.decode()
output_help_lines = output_help.split("\n")
# Check if readme was read at all:
self.assertTrue(readme_help_lines)
self.assertEqual(output_help.count("\n"), len(readme_help_lines))
for i, l in enumerate(readme_help_lines):
self.assertEqual(l, output_help_lines[i])
# Cannot set terminal columns on windows, so simply skip this:
if not platform.system() == "Windows":
for arg in args:
p = subprocess.run(
["dyn2py", arg], capture_output=True, shell=True)
output_help = p.stdout.decode()
output_help_lines = output_help.split("\n")
self.assertEqual(
output_help.count("\n"),
len(readme_help_lines))
for i, l in enumerate(readme_help_lines):
self.assertEqual(l, output_help_lines[i])