Platform independent tests

This commit is contained in:
2023-03-24 16:55:00 +01:00
parent 56872fd575
commit d2d27832f9
4 changed files with 16 additions and 13 deletions

View File

@@ -316,8 +316,8 @@ class DynamoFile(File):
self.python_nodes.remove(python_node_in_file)
self.python_nodes.add(python_node)
# Update the dict:
node_dict["Code"] = python_node.code
# Update the dict, Dyn files are always CRLF:
node_dict["Code"] = "\r\n".join(python_node.code)
self.modified = True
@@ -370,8 +370,8 @@ class DynamoFile(File):
class PythonFile(File):
"""A Python file, subclass of File()"""
code: str
"""The python code as a string."""
code: list[str]
"""The python code."""
header_data: dict
"""Parsed dict from the header of a python file."""
text: str
@@ -431,7 +431,7 @@ class PythonFile(File):
header_string,
HEADER_SEPARATOR,
header_wrapper,
python_node.code
os.linesep.join(python_node.code)
])
self.code = python_node.code
@@ -489,7 +489,7 @@ class PythonFile(File):
raise PythonFileException("Error reading header!")
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)
logging.debug(f"Header data from python file: {self.header_data}")
@@ -563,7 +563,7 @@ class PythonNode():
"""The id of the node"""
engine: str
"""The engine of the node, IronPython2 or CPython3"""
code: str
code: list[str]
"""The full code"""
checksum: str
"""The checksum of the code, for checking changes"""
@@ -599,7 +599,8 @@ class PythonNode():
else:
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:
self.name = next(
@@ -618,6 +619,7 @@ class PythonNode():
"_".join(filename_parts) + ".py")
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:
self.id = python_file.header_data["py_id"]
self.engine = python_file.header_data["py_engine"]
@@ -629,4 +631,5 @@ class PythonNode():
raise PythonNodeException
# 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()