nerdocs / pydifact

A python EDIFACT library.
MIT License
156 stars 45 forks source link

Parser drops UNA Segments while converting tokens to segments #56

Closed mj0nez closed 1 year ago

mj0nez commented 1 year ago

Consider an interchange like

UNA:+.? '
UNB+UNOC:1+1234+3333+200102:2212+42'
UNH+42z42+PAORES:93:1:IA'
UNT+2+42z42'
UNZ+1+42'

While the Parser correctly uses the given control characters to convert the tokens to Segments, it does not pass on the UNA Segment to the created Interchange. Therefore, the interchange has no knowledge of any from the default set differing characters:

./tests/test_segmentcollection.py::test_interchange_with_custom_character Failed: [undefined]AssertionError: assert ',' == '.'
  - .
  + ,
def test_interchange_with_custom_character():
        i = Interchange.from_str(
            "UNA:+.? '"
            "UNB+UNOC:1+1234+3333+200102:2212+42'"
            "UNH+42z42+PAORES:93:1:IA'"
            "UNT+2+42z42'"
            "UNZ+1+42'"
        )
>       assert i.characters.decimal_point == "."
E       AssertionError: assert ',' == '.'
E         - .
E         + ,

tests\test_segmentcollection.py:264: AssertionError

or that an UNA segment was parsed:

./tests/test_segmentcollection.py::test_interchange_with_una Failed: [undefined]assert False
 +  where False = <pydifact.segmentcollection.Interchange object at 0x0000010EF8F34B50>.has_una_segment
def test_interchange_with_una():
        i = Interchange.from_str(
            "UNA:+,? '"
            "UNB+UNOC:1+1234+3333+200102:2212+42'"
            "UNH+42z42+PAORES:93:1:IA'"
            "UNT+2+42z42'"
            "UNZ+1+42'"
        )
>       assert i.has_una_segment
E       assert False
E        +  where False = <pydifact.segmentcollection.Interchange object at 0x0000010EF8F34B50>.has_una_segment

tests\test_segmentcollection.py:253: AssertionError

The docstring of convert_tokens_to_segments hints, that passing information of any parsed UNA was intended but has not been implemented yet.

nerdoc commented 1 year ago

fixed by #57