Exemplo 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
Exemplo 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"]]
Exemplo 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)
Exemplo n.º 4
0
def test_empty_segment_list():
    m = RawSegmentCollection()
    assert m.serialize() == ""
Exemplo 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")
Exemplo 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
Exemplo 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
Exemplo n.º 8
0
def test_get_segments_doesnt_exist():
    collection = RawSegmentCollection()
    segments = list(collection.get_segments("36CF"))
    assert [] == segments
Exemplo n.º 9
0
def test_create_with_segments():
    collection = RawSegmentCollection.from_segments([Segment("36CF")])
    assert [Segment("36CF")] == collection.segments
Exemplo n.º 10
0
def test_malformed_tag5():
    with pytest.raises(EDISyntaxError):
        RawSegmentCollection.from_str("IMD+F++:::This is '-:malformed string'")
Exemplo n.º 11
0
def test_empty_segment():
    m = RawSegmentCollection()
    m.add_segment(Segment("", []))
    assert m
Exemplo n.º 12
0
def test_get_segment_doesnt_exist():
    collection = RawSegmentCollection()
    segment = collection.get_segment("36CF")
    assert segment is None
Exemplo 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