mirror of
https://github.com/infeeeee/dyn2py
synced 2025-12-16 22:16:18 +01:00
More tests
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -3,7 +3,7 @@
|
|||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
- [ ] Commandline
|
- [ ] Commandline
|
||||||
- [ ] File
|
- [x] File
|
||||||
- [ ] DynamoFile
|
- [ ] DynamoFile
|
||||||
- [ ] PythonFile
|
- [ ] PythonFile
|
||||||
- [x] PythonNode
|
- [x] PythonNode
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import pathlib
|
import pathlib
|
||||||
|
import dyn2py
|
||||||
|
|
||||||
INPUT_DIR = "tests/input_files"
|
INPUT_DIR = "tests/input_files"
|
||||||
OUTPUT_DIR = "tests/output_files"
|
OUTPUT_DIR = "tests/output_files"
|
||||||
@@ -10,3 +11,15 @@ def cleanup_output_dir():
|
|||||||
f.unlink()
|
f.unlink()
|
||||||
else:
|
else:
|
||||||
output_dir.mkdir()
|
output_dir.mkdir()
|
||||||
|
|
||||||
|
|
||||||
|
def extract_single_node_dyn():
|
||||||
|
"""Extract python from single_node.dyn
|
||||||
|
File will be here: f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py"
|
||||||
|
"""
|
||||||
|
cleanup_output_dir()
|
||||||
|
|
||||||
|
# Extract py:
|
||||||
|
options = dyn2py.Options(python_folder=OUTPUT_DIR)
|
||||||
|
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn")
|
||||||
|
dyn.extract_python(options)
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ from tests.support import *
|
|||||||
|
|
||||||
class TestFile(unittest.TestCase):
|
class TestFile(unittest.TestCase):
|
||||||
|
|
||||||
# Methods to test:
|
|
||||||
# is_dynamo_file
|
|
||||||
# is_python_file
|
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
paths = [
|
paths = [
|
||||||
f"{INPUT_DIR}/python_nodes.dyn",
|
f"{INPUT_DIR}/python_nodes.dyn",
|
||||||
@@ -65,8 +61,12 @@ class TestFile(unittest.TestCase):
|
|||||||
self.assertFalse(the_file.modified)
|
self.assertFalse(the_file.modified)
|
||||||
|
|
||||||
def test_newer(self):
|
def test_newer(self):
|
||||||
|
# Touch a file, so it will be always newer than the others:
|
||||||
|
touched_file = pathlib.Path(f"{OUTPUT_DIR}/touched_file.py")
|
||||||
|
touched_file.touch()
|
||||||
|
newer_file = dyn2py.File(touched_file)
|
||||||
|
|
||||||
older_file = dyn2py.File(f"{INPUT_DIR}/python_nodes.dyn")
|
older_file = dyn2py.File(f"{INPUT_DIR}/python_nodes.dyn")
|
||||||
newer_file = dyn2py.File(f"{INPUT_DIR}/no_python.dyn")
|
|
||||||
nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.dyn")
|
nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.dyn")
|
||||||
|
|
||||||
self.assertTrue(newer_file.is_newer(older_file))
|
self.assertTrue(newer_file.is_newer(older_file))
|
||||||
@@ -88,3 +88,21 @@ class TestFile(unittest.TestCase):
|
|||||||
|
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
nonexisting_file.write(options)
|
nonexisting_file.write(options)
|
||||||
|
|
||||||
|
def test_is_file(self):
|
||||||
|
|
||||||
|
extract_single_node_dyn()
|
||||||
|
|
||||||
|
paths = [
|
||||||
|
(f"{INPUT_DIR}/python_nodes.dyn", "dyn"),
|
||||||
|
(f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py", "py"),
|
||||||
|
(f"README.md", ""),
|
||||||
|
]
|
||||||
|
|
||||||
|
for path, f in paths:
|
||||||
|
file = dyn2py.File(path)
|
||||||
|
|
||||||
|
self.assertEqual(file.is_dynamo_file(), f=="dyn")
|
||||||
|
self.assertEqual(file.is_python_file(), f=="py")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,12 +32,7 @@ class TestPythonNode(unittest.TestCase):
|
|||||||
|
|
||||||
def test_init_from_py(self):
|
def test_init_from_py(self):
|
||||||
|
|
||||||
cleanup_output_dir()
|
extract_single_node_dyn()
|
||||||
|
|
||||||
# Extract py:
|
|
||||||
options = dyn2py.Options(python_folder=OUTPUT_DIR)
|
|
||||||
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn")
|
|
||||||
dyn.extract_python(options)
|
|
||||||
|
|
||||||
# Open the extracted file and replace a string:
|
# Open the extracted file and replace a string:
|
||||||
with open(f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py") as orig_py, \
|
with open(f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py") as orig_py, \
|
||||||
|
|||||||
Reference in New Issue
Block a user