Skip to content

Commit 63b9e22

Browse files
committed
Add segment comparison tests for UNAv1
1 parent a4cd2ea commit 63b9e22

File tree

6 files changed

+52
-17
lines changed

6 files changed

+52
-17
lines changed

tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def path():
8+
return os.path.dirname(os.path.realpath(__file__)) + "/data"

tests/messagetypes/medrpt/__init__.py

Whitespace-only changes.

tests/segments/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,30 @@
1313
#
1414
# You should have received a copy of the GNU Lesser General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
import pytest
17-
from pydifact.control import Characters
1816

1917

20-
class Setup:
21-
pass
18+
from pydifact import Segment
19+
from pydifact.syntax.v1 import UNASegment
2220

2321

24-
@pytest.fixture
25-
def setup():
26-
setup = Setup()
27-
una_segment = "UNA:+.? '"
28-
setup.cc = Characters.from_str(una_segment)
29-
return setup
22+
def test_compare_against_str():
23+
u = UNASegment(":+.? '")
24+
assert u == ":+.? '"
25+
u = UNASegment("123456")
26+
assert u == "123456"
3027

3128

32-
def test_una_segment(setup):
33-
assert setup.cc.component_separator == ":"
34-
assert setup.cc.data_separator == "+"
35-
assert setup.cc.decimal_point == "."
36-
assert setup.cc.escape_character == "?"
37-
assert setup.cc.reserved_character == " "
38-
assert setup.cc.segment_terminator == "'"
29+
def test_compare_against_same_segment():
30+
assert UNASegment(":+.? '") == UNASegment(":+.? '")
31+
assert UNASegment("123456") == UNASegment("123456")
32+
33+
34+
def test_compare_against_other_segment():
35+
assert UNASegment(":+.? '") != UNASegment("123456")
36+
# change single chars
37+
assert UNASegment(":+.? '") != UNASegment(":+.? `") # backtick!
38+
assert UNASegment(":+.? '") != UNASegment(";+.? `") # colon
39+
40+
41+
def test_compare_against_other_segment_type():
42+
assert UNASegment(":+.? '") != Segment("FOO", "123456")

tests/test_characters.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616

1717
import pytest
1818
from pydifact.control import Characters
19+
import pytest
20+
from pydifact.control import Characters
21+
22+
23+
class Setup:
24+
pass
25+
26+
27+
@pytest.fixture
28+
def setup():
29+
setup = Setup()
30+
una_segment = "UNA:+.? '"
31+
setup.cc = Characters.from_str(una_segment)
32+
return setup
33+
34+
35+
def test_una_segment(setup):
36+
assert setup.cc.component_separator == ":"
37+
assert setup.cc.data_separator == "+"
38+
assert setup.cc.decimal_point == "."
39+
assert setup.cc.escape_character == "?"
40+
assert setup.cc.reserved_character == " "
41+
assert setup.cc.segment_terminator == "'"
1942

2043

2144
def test_with_separator_identity():

0 commit comments

Comments
 (0)