Skip to content

Commit

Permalink
Fix testing with tox on windows (#517)
Browse files Browse the repository at this point in the history
* tox: forward required env.vars to tests

* Replace filecmp.cmp by line-ending-neutral version

* Make linter happy.
  • Loading branch information
dalito authored Apr 5, 2023
1 parent e6ae0f0 commit 22eebdf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import difflib
import math
from pathlib import Path
from typing import List
Expand Down Expand Up @@ -128,3 +129,14 @@ def object_is_subsumed_by_member_of(obj: YAMLRoot, obj_list: List[YAMLRoot], **k
if object_subsumed_by(o, obj, **kwargs):
return True
return False


def filecmp_difflib(left_path: Path, right_path: Path) -> bool:
"""Platfom neutral filecmp.cmp(..) function for text files
Files are read in text mode to ignore newline differences.
"""
with open(left_path) as left, open(right_path) as right:
diff = difflib.unified_diff(left.readlines(), right.readlines())

return list(diff) == []
4 changes: 2 additions & 2 deletions tests/test_implementations/test_pronto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import filecmp
import logging
import unittest

Expand Down Expand Up @@ -37,6 +36,7 @@
ORGANELLE_MEMBRANE,
OUTPUT_DIR,
VACUOLE,
filecmp_difflib,
)
from tests.test_implementations import ComplianceTester

Expand Down Expand Up @@ -377,7 +377,7 @@ def test_sort_order_no_edits(self):
oi = ProntoImplementation(resource)
OUTPUT_DIR.mkdir(exist_ok=True)
oi.dump(output_path, syntax="obo")
self.assertTrue(filecmp.cmp(input_path, output_path))
self.assertTrue(filecmp_difflib(input_path, output_path))

def test_reflexive_diff(self):
self.compliance_tester.test_reflexive_diff(self.oi)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_implementations/test_simple_obo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import filecmp
import logging
import unittest
from copy import deepcopy
Expand Down Expand Up @@ -52,6 +51,7 @@
ORGANELLE_MEMBRANE,
OUTPUT_DIR,
VACUOLE,
filecmp_difflib,
)
from tests.test_implementations import ComplianceTester

Expand Down Expand Up @@ -351,11 +351,11 @@ def test_sort_order_no_edits(self):
oi = SimpleOboImplementation(resource)
OUTPUT_DIR.mkdir(exist_ok=True)
oi.dump(output_path, syntax="obo")
self.assertTrue(filecmp.cmp(input_path, output_path))
self.assertTrue(filecmp_difflib(input_path, output_path))
# try ordering stanzas (but do not ordering within a stanza)
oi.obo_document.order_stanzas()
oi.dump(output_path, syntax="obo")
self.assertTrue(filecmp.cmp(input_path, output_path))
self.assertTrue(filecmp_difflib(input_path, output_path))

@unittest.skip(
"Currently not guaranteed same as OWLAPI: see https://github.com/owlcollab/oboformat/issues/138"
Expand All @@ -371,7 +371,7 @@ def test_sort_order_with_forced_reorder(self):
oi.obo_document.normalize_line_order()
OUTPUT_DIR.mkdir(exist_ok=True)
oi.dump(output_path, syntax="obo")
self.assertTrue(filecmp.cmp(input_path, output_path))
self.assertTrue(filecmp_difflib(input_path, output_path))

def test_merge(self):
resource1 = OntologyResource(slug=TEST_ONT, directory=INPUT_DIR, local=True)
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ envlist =
py

[testenv]
# forward env.vars to tox env for tests\test_implementations\test_sqldb.py
passenv =
LNAME
LOGNAME
USER
USERNAME
commands =
coverage run -p -m pytest --durations=20 {posargs:tests}
coverage combine
Expand Down

0 comments on commit 22eebdf

Please sign in to comment.