def _test_file_read(self, file_name: str, encoding: str = 'iso8859-1'): # read in a complete message from a file message = Message.from_file(file_name) output = message.serialize() with open(file_name, encoding) as file: expected = file.read() # .replace("\n", "") self.assertEqual(expected, output)
def test_wikipedia_file(): message = Message.from_file("{}/wikipedia.edi".format(path)) # make some checks assert message.get_segment("UNB") == Segment("UNB", ["IATB", "1"], "6XPPC", "LHPPC", ["940101", "0950"], "1") assert message.get_segment("IFT") == Segment("IFT", "3", "XYZCOMPANY AVAILABILITY") assert message.get_segment("TVL") == Segment( "TVL", ["240493", "1000", "", "1220"], "FRA", "JFK", "DL", "400", "C")
def test_huge_message(self): """tests parsing a huge message""" message = Message.from_file('data/huge_file2.edi')
def test_from_file(self): with self.assertRaises(FileNotFoundError): Message.from_file("/no/such/file")
from pydifact.message import Message message = Message.from_file("../input/20200506 0432_API_50157_YY123_IAD_BRU_20200506 1700.txt") for segment in message.segments: print('Segment tag: {}, content: {}'.format( segment.tag, segment.elements))