mirror of
https://github.com/infeeeee/dyn2py
synced 2025-12-16 22:16:18 +01:00
Windows test fixes
This commit is contained in:
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|||||||
import simplejson as json
|
import simplejson as json
|
||||||
import hashlib
|
import hashlib
|
||||||
import pathlib
|
import pathlib
|
||||||
import textwrap
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -399,10 +398,10 @@ class PythonFile(File):
|
|||||||
# Do not read from disk:
|
# Do not read from disk:
|
||||||
super().__init__(filepath, read_from_disk=False)
|
super().__init__(filepath, read_from_disk=False)
|
||||||
|
|
||||||
header_notice = """\
|
header_notice = os.linesep.join([
|
||||||
This file was generated with dyn2py from a Dynamo graph.
|
"This file was generated with dyn2py from a Dynamo graph.",
|
||||||
Do not edit this section, if you want to update the Dynamo graph!\
|
"Do not edit this section, if you want to update the Dynamo graph!"
|
||||||
"""
|
])
|
||||||
|
|
||||||
# Double escape path:
|
# Double escape path:
|
||||||
dyn_path_string = str(dynamo_file.realpath)
|
dyn_path_string = str(dynamo_file.realpath)
|
||||||
@@ -420,14 +419,14 @@ class PythonFile(File):
|
|||||||
"py_engine": python_node.engine
|
"py_engine": python_node.engine
|
||||||
}
|
}
|
||||||
|
|
||||||
header_string = "\r\n".join(
|
header_string = os.linesep.join(
|
||||||
[f"{k}:{self.header_data[k]}" for k in self.header_data])
|
[f"{k}:{self.header_data[k]}" for k in self.header_data])
|
||||||
header_wrapper = '"""'
|
header_wrapper = '"""'
|
||||||
|
|
||||||
self.text = "\r\n".join([
|
self.text = os.linesep.join([
|
||||||
header_wrapper,
|
header_wrapper,
|
||||||
HEADER_SEPARATOR,
|
HEADER_SEPARATOR,
|
||||||
textwrap.dedent(header_notice),
|
header_notice,
|
||||||
HEADER_SEPARATOR,
|
HEADER_SEPARATOR,
|
||||||
header_string,
|
header_string,
|
||||||
HEADER_SEPARATOR,
|
HEADER_SEPARATOR,
|
||||||
@@ -462,7 +461,8 @@ class PythonFile(File):
|
|||||||
|
|
||||||
logging.info(f"Reading file: {self.filepath}")
|
logging.info(f"Reading file: {self.filepath}")
|
||||||
with open(self.filepath, mode="r", newline="", encoding="utf-8") as input_py:
|
with open(self.filepath, mode="r", newline="", encoding="utf-8") as input_py:
|
||||||
python_lines = input_py.readlines()
|
python_lines = [line.strip("\r\n")
|
||||||
|
for line in input_py.readlines()]
|
||||||
|
|
||||||
self.text = os.linesep.join(python_lines)
|
self.text = os.linesep.join(python_lines)
|
||||||
self.header_data = {}
|
self.header_data = {}
|
||||||
@@ -470,7 +470,6 @@ class PythonFile(File):
|
|||||||
code_start_line = 0
|
code_start_line = 0
|
||||||
|
|
||||||
for i, line in enumerate(python_lines):
|
for i, line in enumerate(python_lines):
|
||||||
line = line.strip()
|
|
||||||
logging.debug(f"Reading line: {line}")
|
logging.debug(f"Reading line: {line}")
|
||||||
|
|
||||||
# Skip the first lines:
|
# Skip the first lines:
|
||||||
@@ -490,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 = "".join(python_lines[code_start_line:])
|
self.code = os.linesep.join(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}")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import unittest
|
|||||||
import dyn2py
|
import dyn2py
|
||||||
import shutil
|
import shutil
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import os
|
||||||
|
|
||||||
from tests.support import *
|
from tests.support import *
|
||||||
|
|
||||||
@@ -11,8 +12,7 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
def test_init(self):
|
def test_init(self):
|
||||||
extract_single_node_dyn()
|
extract_single_node_dyn()
|
||||||
|
|
||||||
py1 = dyn2py.PythonFile(
|
py1 = dyn2py.PythonFile(f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
||||||
f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
|
||||||
|
|
||||||
dyn2py.DynamoFile.open_files.clear()
|
dyn2py.DynamoFile.open_files.clear()
|
||||||
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn")
|
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn")
|
||||||
@@ -22,8 +22,8 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
|
|
||||||
for py in [py1, py2]:
|
for py in [py1, py2]:
|
||||||
|
|
||||||
self.assertEqual(len(py.code.split("\n")), 17)
|
self.assertEqual(len(py.code.split(os.linesep)), 17)
|
||||||
self.assertEqual(len(py.text.split("\r\n")), 31)
|
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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user