Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newline/encoding issues causing tests to fail on Windows #379

Closed
goodmami opened this issue Dec 9, 2023 · 2 comments
Closed

Newline/encoding issues causing tests to fail on Windows #379

goodmami opened this issue Dec 9, 2023 · 2 comments
Labels

Comments

@goodmami
Copy link
Member

goodmami commented Dec 9, 2023

It looks like newline issues are causing problems with running tests on windows:

     def test_update(self, single_item_table):
        table = single_item_table
>       assert table[0] == (0, 'The dog barks.')
E       AssertionError: assert <Row object (...2284478645696> == (0, 'The dog barks.')
E         At index 1 diff: 'The dog barks.\r' != 'The dog barks.'
E         Full diff:
E         - (0, 'The dog barks.')
E         + <Row object (0, 'The dog barks.\r') at 2284478645696>

This seems to affect the tsdb and tdl tests.

@goodmami
Copy link
Member Author

goodmami commented Dec 11, 2023

The reason for errors in the tdl_test.py file is that the testing file writes to disk without specifying an encoding. This isn't a bug in PyDelphin proper, just in the tests.

def _iterparse(s):
with tempfile.TemporaryDirectory() as dir:
path = os.path.join(dir, 'tmp.tdl')
with open(path, 'w') as fh:
print(s, file=fh)
yield from tdl.iterparse(path)

@goodmami
Copy link
Member Author

For the TSDB tests, the issue was similar in that the code is fine but the tests are buggy for Windows. In this case it's the use of Pathlib.Path.write_text() to write the testsuite files:

@pytest.fixture
def empty_testsuite(tmp_path):
ts = tmp_path.joinpath('empty')
ts.mkdir()
ts.joinpath('relations').write_text(_simple_relations)
return ts

The write_text() method does not allow one to specify the newline parameter prior to Python 3.10 and it defaults to the system sequence. The solution here is to make a function that does a regular open on the files with newline="\n".

I think it is true that TSDB database files invariably use \n as line endings and never \r\n, even on Windows systems, but I cannot find a definitive source for that at the moment.

@goodmami goodmami changed the title Newline issues causing tests to fail on Windows Newline/encoding issues causing tests to fail on Windows Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant