def test_count_none_fields_as_empty_strings(self): self.assertEqual(b'|B|', codec.encode_record([None, 'B', None], 'ascii'))
def test_encode_record(self): msg = b'A|B^C\D^E|F^G|H' record = codec.decode_record(msg, 'ascii') self.assertEqual(msg, codec.encode_record(record, 'ascii'))
def test_encode_record_with_none_and_non_string(self): msg = ['foo', None, 0] res = b'foo||0' self.assertEqual(res, codec.encode_record(msg, 'ascii'))
# # Copyright (C) 2012 Alexander Shorin # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. # import datetime import unittest from astm import codec from astm import omnilab from astm.constants import ENCODING decode_record = lambda r: codec.decode_record(r.encode(), ENCODING) encode_record = lambda r: codec.encode_record(r, ENCODING) class OmnilabTestCase(unittest.TestCase): def test_header_request(self): data = 'H|\^&|||HOST^1.0.0|||||||P|E 1394-97|20091116104731' header = omnilab.client.Header(*decode_record(data)) self.assertEqual(header.type, 'H') self.assertEqual(header.sender.name, 'HOST') self.assertEqual(header.sender.version, '1.0.0') self.assertEqual(header.version, 'E 1394-97') self.assertEqual(header.timestamp, datetime.datetime(2009, 11, 16, 10, 47, 31)) def test_header_response(self):
# # Copyright (C) 2012 Alexander Shorin # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. # import datetime import unittest from astm import codec from astm import omnilab from astm.constants import ENCODING decode_record = lambda r: codec.decode_record(r.encode(), ENCODING) encode_record = lambda r: codec.encode_record(r, ENCODING) class OmnilabTestCase(unittest.TestCase): def test_header_request(self): data = 'H|\^&|||HOST^1.0.0|||||||P|E 1394-97|20091116104731' header = omnilab.client.Header(*decode_record(data)) self.assertEqual(header.type, 'H') self.assertEqual(header.sender.name, 'HOST') self.assertEqual(header.sender.version, '1.0.0') self.assertEqual(header.version, 'E 1394-97') self.assertEqual(header.timestamp, datetime.datetime(2009, 11, 16, 10, 47, 31)) def test_header_response(self): data = 'H|\^&|||LabOnline^1.0.0|||||||P|E 1394-97|20091116104731'
def test_count_none_fields_as_empty_strings(self): self.assertEqual(b"|B|", codec.encode_record([None, "B", None], "ascii"))
def test_encode_record_with_none_and_non_string(self): msg = ["foo", None, 0] res = b"foo||0" self.assertEqual(res, codec.encode_record(msg, "ascii"))
def test_encode_record(self): msg = b"A|B^C\D^E|F^G|H" record = codec.decode_record(msg, "ascii") self.assertEqual(msg, codec.encode_record(record, "ascii"))