mirror of
https://github.com/infeeeee/dyn2py
synced 2025-12-16 22:16:18 +01:00
Platform independent tests
This commit is contained in:
@@ -316,8 +316,8 @@ class DynamoFile(File):
|
|||||||
self.python_nodes.remove(python_node_in_file)
|
self.python_nodes.remove(python_node_in_file)
|
||||||
self.python_nodes.add(python_node)
|
self.python_nodes.add(python_node)
|
||||||
|
|
||||||
# Update the dict:
|
# Update the dict, Dyn files are always CRLF:
|
||||||
node_dict["Code"] = python_node.code
|
node_dict["Code"] = "\r\n".join(python_node.code)
|
||||||
|
|
||||||
self.modified = True
|
self.modified = True
|
||||||
|
|
||||||
@@ -370,8 +370,8 @@ class DynamoFile(File):
|
|||||||
class PythonFile(File):
|
class PythonFile(File):
|
||||||
"""A Python file, subclass of File()"""
|
"""A Python file, subclass of File()"""
|
||||||
|
|
||||||
code: str
|
code: list[str]
|
||||||
"""The python code as a string."""
|
"""The python code."""
|
||||||
header_data: dict
|
header_data: dict
|
||||||
"""Parsed dict from the header of a python file."""
|
"""Parsed dict from the header of a python file."""
|
||||||
text: str
|
text: str
|
||||||
@@ -431,7 +431,7 @@ class PythonFile(File):
|
|||||||
header_string,
|
header_string,
|
||||||
HEADER_SEPARATOR,
|
HEADER_SEPARATOR,
|
||||||
header_wrapper,
|
header_wrapper,
|
||||||
python_node.code
|
os.linesep.join(python_node.code)
|
||||||
])
|
])
|
||||||
|
|
||||||
self.code = python_node.code
|
self.code = python_node.code
|
||||||
@@ -489,7 +489,7 @@ class PythonFile(File):
|
|||||||
raise PythonFileException("Error reading header!")
|
raise PythonFileException("Error reading header!")
|
||||||
self.header_data[line[0:sl]] = line[sl+1:]
|
self.header_data[line[0:sl]] = line[sl+1:]
|
||||||
|
|
||||||
self.code = os.linesep.join(python_lines[code_start_line:])
|
self.code = python_lines[code_start_line:]
|
||||||
self.open_files.add(self)
|
self.open_files.add(self)
|
||||||
|
|
||||||
logging.debug(f"Header data from python file: {self.header_data}")
|
logging.debug(f"Header data from python file: {self.header_data}")
|
||||||
@@ -563,7 +563,7 @@ class PythonNode():
|
|||||||
"""The id of the node"""
|
"""The id of the node"""
|
||||||
engine: str
|
engine: str
|
||||||
"""The engine of the node, IronPython2 or CPython3"""
|
"""The engine of the node, IronPython2 or CPython3"""
|
||||||
code: str
|
code: list[str]
|
||||||
"""The full code"""
|
"""The full code"""
|
||||||
checksum: str
|
checksum: str
|
||||||
"""The checksum of the code, for checking changes"""
|
"""The checksum of the code, for checking changes"""
|
||||||
@@ -599,7 +599,8 @@ class PythonNode():
|
|||||||
else:
|
else:
|
||||||
self.engine = "IronPython2"
|
self.engine = "IronPython2"
|
||||||
|
|
||||||
self.code = node_dict_from_dyn["Code"]
|
# It's read from a dynamo file, so separator is always CRLF
|
||||||
|
self.code = node_dict_from_dyn["Code"].split("\r\n")
|
||||||
|
|
||||||
# Get the name of the node:
|
# Get the name of the node:
|
||||||
self.name = next(
|
self.name = next(
|
||||||
@@ -618,6 +619,7 @@ class PythonNode():
|
|||||||
"_".join(filename_parts) + ".py")
|
"_".join(filename_parts) + ".py")
|
||||||
self.filepath = dynamo_file.dirpath.joinpath(self.filename)
|
self.filepath = dynamo_file.dirpath.joinpath(self.filename)
|
||||||
|
|
||||||
|
# Initialize from a python file:
|
||||||
elif python_file and not node_dict_from_dyn and not dynamo_file:
|
elif python_file and not node_dict_from_dyn and not dynamo_file:
|
||||||
self.id = python_file.header_data["py_id"]
|
self.id = python_file.header_data["py_id"]
|
||||||
self.engine = python_file.header_data["py_engine"]
|
self.engine = python_file.header_data["py_engine"]
|
||||||
@@ -629,4 +631,5 @@ class PythonNode():
|
|||||||
raise PythonNodeException
|
raise PythonNodeException
|
||||||
|
|
||||||
# Calculate checksum:
|
# Calculate checksum:
|
||||||
self.checksum = hashlib.md5(self.code.encode()).hexdigest()
|
checksums = [hashlib.md5(l.encode()).hexdigest() for l in self.code]
|
||||||
|
self.checksum = hashlib.md5("".join(checksums).encode()).hexdigest()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
self.assertEqual(len(dyn.python_nodes), 6)
|
self.assertEqual(len(dyn.python_nodes), 6)
|
||||||
self.assertTrue(py_node)
|
self.assertTrue(py_node)
|
||||||
self.assertIn(py_node, dyn.python_nodes)
|
self.assertIn(py_node, dyn.python_nodes)
|
||||||
self.assertEqual(py_node.checksum, "1f3d9e6153804fe1ed37571a9cda8e26")
|
self.assertEqual(py_node.checksum, "e830a6ae6b395bcfd4e5a40da48f3bfc")
|
||||||
|
|
||||||
with self.assertRaises(dyn2py.PythonNodeNotFoundException):
|
with self.assertRaises(dyn2py.PythonNodeNotFoundException):
|
||||||
dyn.get_python_node_by_id("wrongid")
|
dyn.get_python_node_by_id("wrongid")
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
|
|
||||||
for py in [py1, py2]:
|
for py in [py1, py2]:
|
||||||
|
|
||||||
self.assertEqual(len(py.code.split(os.linesep)), 17)
|
self.assertEqual(len(py.code), 17)
|
||||||
self.assertEqual(len(py.text.split(os.linesep)), 32, msg=py.filepath)
|
self.assertEqual(len(py.text.split(os.linesep)), 32, msg=py.filepath)
|
||||||
self.assertIs(type(py.header_data), dict)
|
self.assertIs(type(py.header_data), dict)
|
||||||
self.assertTrue(py in dyn2py.PythonFile.open_files)
|
self.assertTrue(py in dyn2py.PythonFile.open_files)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class TestPythonNode(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(node.id, "1c5d99792882409e97e132b3e9f814b0")
|
self.assertEqual(node.id, "1c5d99792882409e97e132b3e9f814b0")
|
||||||
self.assertEqual(node.engine, "CPython3")
|
self.assertEqual(node.engine, "CPython3")
|
||||||
self.assertEqual(node.checksum, "ec2c85a11ddbf8375da03f11272d427a")
|
self.assertEqual(node.checksum, "92d46019bf538072db6bd1287267c147")
|
||||||
self.assertEqual(node.name, "Python Script")
|
self.assertEqual(node.name, "Python Script")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
node.filename, "single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
node.filename, "single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
||||||
@@ -36,7 +36,7 @@ class TestPythonNode(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(node.id, "1c5d99792882409e97e132b3e9f814b0")
|
self.assertEqual(node.id, "1c5d99792882409e97e132b3e9f814b0")
|
||||||
self.assertEqual(node.engine, "CPython3")
|
self.assertEqual(node.engine, "CPython3")
|
||||||
self.assertEqual(node.checksum, "8d9091d24788a6fdfa5e1e109298b50e")
|
self.assertEqual(node.checksum, "64a73c52bd213b6f1b593697cdde789b")
|
||||||
|
|
||||||
def test_init_exception(self):
|
def test_init_exception(self):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user