Skip to content

Commit 1d67e59

Browse files
vladistandalito
authored andcommitted
Convert test_arrays.py to pytest format
- Convert setUp() method to pytest fixtures (normalizer, matrix_data) - Convert test method to standalone function - Convert assertEqual to assert statement
1 parent 0586e36 commit 1d67e59

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import unittest
21
from pathlib import Path
32

3+
import pytest
44
import yaml
55

66
from linkml_runtime.processing.referencevalidator import (
@@ -10,21 +10,26 @@
1010
from tests.test_processing import INPUT_DIR
1111

1212

13-
class ArrayTestCase(unittest.TestCase):
13+
@pytest.fixture
14+
def normalizer():
15+
"""ReferenceValidator instance for array example schema."""
16+
sv = SchemaView(str(Path(INPUT_DIR) / "array_example.yaml"))
17+
return ReferenceValidator(sv)
18+
19+
20+
@pytest.fixture
21+
def matrix_data():
22+
"""Load matrix data from array example data file."""
23+
return yaml.safe_load(open(str(Path(INPUT_DIR) / "array_example_data.yaml")))
24+
25+
26+
def test_array_normalization(normalizer, matrix_data):
1427
"""
15-
Tests array normalization
28+
Test that we can infer the collection form of a slot.
1629
30+
Tests array normalization functionality.
1731
See: https://linkml.io/linkml/howtos/multidimensional-arrays
1832
"""
19-
20-
def setUp(self) -> None:
21-
sv = SchemaView(str(Path(INPUT_DIR) / "array_example.yaml"))
22-
self.normalizer = ReferenceValidator(sv)
23-
self.matrix = yaml.safe_load(open(str(Path(INPUT_DIR) / "array_example_data.yaml")))
24-
25-
def test_array_normalization(self):
26-
"""Test that we can infer the collection form of a slot."""
27-
norm = self.normalizer
28-
matrix = norm.normalize(self.matrix)
29-
vals = [int(x) for x in matrix["temperatures"]]
30-
self.assertEqual([11, 12, 13, 21, 22, 23, 31, 32, 33], vals)
33+
matrix = normalizer.normalize(matrix_data)
34+
vals = [int(x) for x in matrix["temperatures"]]
35+
assert vals == [11, 12, 13, 21, 22, 23, 31, 32, 33]

0 commit comments

Comments
 (0)