From 17f6204b8a0f69f32aab792d2b6e17d0cacaacff Mon Sep 17 00:00:00 2001 From: infeeeee Date: Wed, 8 Mar 2023 14:39:13 +0100 Subject: [PATCH] Working on tests --- tests/test_CommandLine.py | 31 +++++++++++++++++++++++++++++++ tests/test_DynamoFile.py | 16 ++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 tests/test_CommandLine.py diff --git a/tests/test_CommandLine.py b/tests/test_CommandLine.py new file mode 100644 index 0000000..91c5f38 --- /dev/null +++ b/tests/test_CommandLine.py @@ -0,0 +1,31 @@ +import unittest +import subprocess + + +class TestCommandLine(unittest.TestCase): + def test_help(self): + args = ["-h", "--help"] + readme_help_lines = [] + + # Read help from readme: + with open("README.md", mode="r", encoding="utf-8") as readme: + is_help_line = False + + for line in readme.readlines(): + if line == "> dyn2py --help": + is_help_line = True + elif is_help_line and line == "```": + # It's the end of the help + break + elif is_help_line: + readme_help_lines.append(line) + + 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]) diff --git a/tests/test_DynamoFile.py b/tests/test_DynamoFile.py index e7df33d..ce66879 100644 --- a/tests/test_DynamoFile.py +++ b/tests/test_DynamoFile.py @@ -1,13 +1,11 @@ -import os import unittest import dyn2py import pathlib - INPUT_DIR = "tests/input_files" OUTPUT_DIR = "tests/output_files" -def cleanup(): +def cleanup_output_dir(): output_dir = pathlib.Path(OUTPUT_DIR) if output_dir.exists(): for f in output_dir.iterdir(): @@ -17,6 +15,12 @@ def cleanup(): class TestDynamoFile(unittest.TestCase): + # Missing methods: + # get_related_python_files + # get_open_file_by_uuid + # update_python_node + # write + def test_read(self): dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn") dyn.read() @@ -39,11 +43,11 @@ class TestDynamoFile(unittest.TestCase): dyn.get_python_node_by_id("wrongid") def test_extract_python(self): - cleanup() + cleanup_output_dir() - opt = dyn2py.Options(python_folder="tests/output_files") + opt = dyn2py.Options(python_folder=OUTPUT_DIR) dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn") dyn.extract_python(options=opt) - output_dir = pathlib.Path("tests/output_files") + output_dir = pathlib.Path(OUTPUT_DIR) self.assertEqual(len(list(output_dir.iterdir())), 6)