mirror of
https://github.com/infeeeee/dyn2py
synced 2025-12-16 22:16:18 +01:00
Working on tests
This commit is contained in:
31
tests/test_CommandLine.py
Normal file
31
tests/test_CommandLine.py
Normal file
@@ -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])
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
import os
|
|
||||||
import unittest
|
import unittest
|
||||||
import dyn2py
|
import dyn2py
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
INPUT_DIR = "tests/input_files"
|
INPUT_DIR = "tests/input_files"
|
||||||
OUTPUT_DIR = "tests/output_files"
|
OUTPUT_DIR = "tests/output_files"
|
||||||
|
|
||||||
def cleanup():
|
def cleanup_output_dir():
|
||||||
output_dir = pathlib.Path(OUTPUT_DIR)
|
output_dir = pathlib.Path(OUTPUT_DIR)
|
||||||
if output_dir.exists():
|
if output_dir.exists():
|
||||||
for f in output_dir.iterdir():
|
for f in output_dir.iterdir():
|
||||||
@@ -17,6 +15,12 @@ def cleanup():
|
|||||||
|
|
||||||
class TestDynamoFile(unittest.TestCase):
|
class TestDynamoFile(unittest.TestCase):
|
||||||
|
|
||||||
|
# Missing methods:
|
||||||
|
# get_related_python_files
|
||||||
|
# get_open_file_by_uuid
|
||||||
|
# update_python_node
|
||||||
|
# write
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn")
|
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn")
|
||||||
dyn.read()
|
dyn.read()
|
||||||
@@ -39,11 +43,11 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
dyn.get_python_node_by_id("wrongid")
|
dyn.get_python_node_by_id("wrongid")
|
||||||
|
|
||||||
def test_extract_python(self):
|
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 = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn")
|
||||||
dyn.extract_python(options=opt)
|
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)
|
self.assertEqual(len(list(output_dir.iterdir())), 6)
|
||||||
|
|||||||
Reference in New Issue
Block a user