Ejemplo n.º 1
0
    def test_block_writer_multiple_attributes(self):
        # Given
        items = list()

        record_map = _Record.create()

        dog_map = _Record.create()
        dog_map.add(Slot.create_slot(Text.create_from('dog'), Text.create_from('bark')))
        record_map.add(Attr.create_attr(Text.create_from('Animal'), dog_map))

        cat_map = _Record.create()
        cat_map.add(Slot.create_slot(Text.create_from('cat'), Text.create_from('meow')))
        record_map.add(Attr.create_attr(Text.create_from('Animal'), cat_map))

        bird_map = _Record.create()
        bird_map.add(Slot.create_slot(Text.create_from('bird'), Text.create_from('chirp')))
        record_map.add(Attr.create_attr(Text.create_from('Animal'), bird_map))

        items.append(record_map)
        writer = _ReconWriter()
        # When
        actual = _BlockWriter._write(items, writer=writer, first=True)
        # Then
        self.assertIsInstance(actual, _OutputMessage)
        self.assertEqual('@Animal(dog:bark)@Animal(cat:meow)@Animal(bird:chirp)', actual._message)
Ejemplo n.º 2
0
    def _mold(self, envelope: Optional['_LaneAddressedEnvelope']) -> 'Value':

        if envelope is not None:
            headers = _Record.create()._add_slot('node', envelope._node_uri)._add_slot('lane', envelope._lane_uri)
            return Attr.create_attr(self._tag, headers)._concat(envelope._body)
        else:
            return _Item.extant()
Ejemplo n.º 3
0
 def test_write_record_empty(self):
     # Given
     record = _Record.create()
     writer = _ReconWriter()
     # When
     actual = writer._write_record(record)
     # Then
     self.assertIsNone(actual)
Ejemplo n.º 4
0
 def test_block_writer_nested_attributes(self):
     # Given
     items = list()
     name_record = _Record.create()
     name_record.add(Slot.create_slot(Text.create_from('Name'), Text.create_from('Collie')))
     breed_record = _Record.create()
     breed_record.add(Attr.create_attr(Text.create_from('Breed'), name_record))
     dog_record = _Record.create()
     dog_record.add(Slot.create_slot(Text.create_from('Dog'), breed_record))
     species_record = _Record.create()
     species_record.add(Attr.create_attr(Text.create_from('Species'), dog_record))
     animals_record = _Record.create()
     animals_record.add(Slot.create_slot(Text.create_from('Animals'), species_record))
     items.append(Attr.create_attr(Text.create_from('Zoo'), animals_record))
     writer = _ReconWriter()
     # When
     actual = _BlockWriter._write(items, writer=writer, first=True)
     # Then
     self.assertIsInstance(actual, _OutputMessage)
     self.assertEqual('@Zoo(Animals:@Species(Dog:@Breed(Name:Collie)))', actual._message)
Ejemplo n.º 5
0
 def test_attr_writer_existing_key_and_value_slot(self):
     # Given
     key = Text.create_from('animal')
     value = _Record.create()
     value.add(Slot.create_slot(Text.create_from('dog'), Text.create_from('bark')))
     writer = _ReconWriter()
     # When
     actual = _AttrWriter._write(key=key, writer=writer, value=value)
     # Then
     self.assertIsInstance(actual, _OutputMessage)
     self.assertEqual('@animal(dog:bark)', actual._message)
Ejemplo n.º 6
0
 def test_write_value_record(self):
     # Given
     record = _Record.create()
     record.add(Slot.create_slot(Text.create_from('Cow'), Text.create_from('Moo')))
     writer = _ReconWriter()
     # When
     actual = writer._write_value(record)
     # Then
     self.assertIsInstance(actual, _OutputMessage)
     self.assertEqual(7, actual._size)
     self.assertEqual('Cow:Moo', actual._value)
     self.assertEqual('o', actual._last_char)
Ejemplo n.º 7
0
 def test_write_record_single(self):
     # Given
     record = _Record.create()
     record.add(Text.create_from('Dog'))
     writer = _ReconWriter()
     # When
     actual = writer._write_record(record)
     # Then
     self.assertIsInstance(actual, _OutputMessage)
     self.assertEqual(3, actual._size)
     self.assertEqual('Dog', actual._value)
     self.assertEqual('g', actual._last_char)
Ejemplo n.º 8
0
 def test_block_writer_slot_in_attr(self):
     # Given
     items = list()
     record_map = _Record.create()
     record_map.add(Slot.create_slot(Text.create_from('cat'), Text.create_from('meow')))
     items.append(Attr.create_attr(Text.create_from('animal'), record_map))
     writer = _ReconWriter()
     # When
     actual = _BlockWriter._write(items, writer=writer, first=True)
     # Then
     self.assertIsInstance(actual, _OutputMessage)
     self.assertEqual('@animal(cat:meow)', actual._message)
Ejemplo n.º 9
0
    def _mold(self, envelope: Optional['_LinkAddressedEnvelope']) -> 'Value':

        if envelope is not None:

            headers = _Record.create()._add_slot('node', envelope._node_uri)._add_slot('lane', envelope._lane_uri)
            prio = envelope._prio

            if prio != 0 and not math.isnan(prio):
                headers._add_slot('prio', Num.create_from(prio))

            rate = envelope._rate

            if rate != 0 and not math.isnan(rate):
                headers._add_slot('rate', Num.create_from(rate))

            return Attr.create_attr(self._tag, headers)._concat(envelope._body)
        else:
            return _Item.extant()
Ejemplo n.º 10
0
 def _create_record_builder() -> 'RecordMap':
     return _Record.create()