Esempio n. 1
0
def setup():
    setup = Setup()
    unb_segment = "UNB+UNOA:4+APIS*ABE+USADHS+070429:0900+000000001++USADHS'"
    cc = Characters()
    setup.cc = cc.with_control_character("decimal_point", ".")
    setup.collection = RawSegmentCollection.from_str(unb_segment)
    return setup
Esempio n. 2
0
def test_split_by():
    def _serialize(collections: Iterable[RawSegmentCollection]) -> List[List[str]]:
        lst = []
        global_lst = []
        for collection in collections:
            if lst:
                global_lst.append(lst)
                lst = []
            for segment in collection.segments:
                lst.append(segment.tag)
        if lst:
            global_lst.append(lst)
        return global_lst

    assert _serialize(RawSegmentCollection.from_segments([]).split_by("A")) == []
    collection = RawSegmentCollection.from_segments(
        Segment(i) for i in ["A", "B", "A", "A", "B", "D"]
    )
    assert _serialize(collection.split_by("Z")) == []
    assert _serialize(collection.split_by("A")) == [["A", "B"], ["A"], ["A", "B", "D"]]
    assert _serialize(collection.split_by("A")) == [["A", "B"], ["A"], ["A", "B", "D"]]
Esempio n. 3
0
def test_get_segments_w_predicate():
    collection = RawSegmentCollection.from_segments(
        [
            Segment("A", "1", "a"),
            Segment("A", "2", "b"),
            Segment("A", "1", "c"),
        ]
    )
    segments = collection.get_segments("A", lambda x: x[0] == "1")
    assert [
        Segment("A", "1", "a"),
        Segment("A", "1", "c"),
    ] == list(segments)
Esempio n. 4
0
def test_empty_segment_list():
    m = RawSegmentCollection()
    assert m.serialize() == ""
Esempio n. 5
0
def test_get_segment_w_predicate():
    collection = RawSegmentCollection.from_segments(
        [Segment("36CF", "1"), Segment("36CF", "2")]
    )
    segment = collection.get_segment("36CF", lambda x: x[0] == "2")
    assert segment == Segment("36CF", "2")
Esempio n. 6
0
def test_get_segment():
    collection = RawSegmentCollection.from_segments(
        [Segment("36CF", 1), Segment("36CF", 2)]
    )
    segment = collection.get_segment("36CF")
    assert Segment("36CF", 1) == segment
Esempio n. 7
0
def test_get_segments():
    collection = RawSegmentCollection.from_segments(
        [Segment("36CF", 1), Segment("CPD"), Segment("36CF", 2)]
    )
    segments = list(collection.get_segments("36CF"))
    assert [Segment("36CF", 1), Segment("36CF", 2)] == segments
Esempio n. 8
0
def test_get_segments_doesnt_exist():
    collection = RawSegmentCollection()
    segments = list(collection.get_segments("36CF"))
    assert [] == segments
Esempio n. 9
0
def test_create_with_segments():
    collection = RawSegmentCollection.from_segments([Segment("36CF")])
    assert [Segment("36CF")] == collection.segments
Esempio n. 10
0
def test_malformed_tag5():
    with pytest.raises(EDISyntaxError):
        RawSegmentCollection.from_str("IMD+F++:::This is '-:malformed string'")
Esempio n. 11
0
def test_empty_segment():
    m = RawSegmentCollection()
    m.add_segment(Segment("", []))
    assert m
Esempio n. 12
0
def test_get_segment_doesnt_exist():
    collection = RawSegmentCollection()
    segment = collection.get_segment("36CF")
    assert segment is None
Esempio n. 13
0
def test_str_serialize():
    collection = RawSegmentCollection.from_segments(
        [Segment("36CF", "1"), Segment("36CF", "2")]
    )
    string = str(collection)
    assert "36CF+1'36CF+2'" == string