def __init__(self, config, sequence_n, reciver): self.config = config tag = FileTag(self._year(), sequence_n, self._sender(), reciver, self._version()) transmission = AcknowledgeTransmission(self.config['sender_id'], self.config['sender_name'], self.config['sender_type']) self._acknowledge = CWRFile(tag, transmission)
def test_encoded(self): data = FileTag(year=2015, sequence_n=123, sender='SND', receiver='RCV', version=2.1) encoded = self._encoder.encode(data) self.assertEqual(2015, encoded['year']) self.assertEqual(123, encoded['sequence_n']) self.assertEqual('SND', encoded['sender']) self.assertEqual('RCV', encoded['receiver']) self.assertEqual(2.1, encoded['version'])
def decode(self, file_name): """ Parses the filename, creating a FileTag from it. It will try both the old and the new conventions, if the filename does not conform any of them, then an empty FileTag will be returned. :param file_name: filename to parse :return: a FileTag instance """ try: file_tag = self._filename_decoder_new.decode(file_name) except: try: file_tag = self._filename_decoder_old.decode(file_name) except: file_tag = FileTag(0, 0, '', '', '') return file_tag
def _get_file_tag(self): return FileTag(year=2015, sequence_n=123, sender='SND', receiver='RCV', version=2.1)
def decode(self, data): return FileTag(data['year'], data['sequence_n'], data['sender'], data['receiver'], data['version'])
def test_s3_r3(self): # Sender with 3 digits and receiver with 3 digits data = self._parser.encode(FileTag(2000, 12, 'AB2', '234', 0.2)) self.assertEqual("CW0012AB2_234.V02", data)
def test_s2_r3(self): # Sender with 2 digits and receiver with 3 digits data = self._parser.encode(FileTag(2099, 0, '22', 'DEC', 0)) self.assertEqual("CW990022_DEC.V00", data)
def test_s3_r2(self): # Sender with 3 digits and receiver with 2 digits data = self._parser.encode(FileTag(2013, 1, 'ABC', '23', 2.2)) self.assertEqual("CW1301ABC_23.V22", data)
def test_s2_r2(self): # Sender with 2 digits and receiver with 2 digits data = self._parser.encode(FileTag(2012, 23, '11', '22', 2.1)) self.assertEqual("CW122311_22.V21", data)