예제 #1
0
class TemporalHydrationTestCase(TestCase):
    def setUp(self):
        self.hydrant = PackStreamHydrator(2)

    def test_can_hydrate_date_time_structure(self):
        struct = Structure(b'd', 1539344261, 474716862)
        dt, = self.hydrant.hydrate([struct])
        self.assertEqual(dt.year, 2018)
        self.assertEqual(dt.month, 10)
        self.assertEqual(dt.day, 12)
        self.assertEqual(dt.hour, 11)
        self.assertEqual(dt.minute, 37)
        self.assertEqual(dt.second, 41.474716862)
예제 #2
0
class HydrationTestCase(TestCase):

    def setUp(self):
        self.hydrant = PackStreamHydrator(1)

    def test_can_hydrate_node_structure(self):
        struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
        alice, = self.hydrant.hydrate([struct])
        self.assertEqual(alice.id, 123)
        self.assertEqual(alice.labels, {"Person"})
        self.assertEqual(set(alice.keys()), {"name"})
        self.assertEqual(alice.get("name"), "Alice")

    def test_hydrating_unknown_structure_returns_same(self):
        struct = Structure(b'?', "foo")
        mystery, = self.hydrant.hydrate([struct])
        self.assertEqual(mystery, struct)

    def test_can_hydrate_in_list(self):
        struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
        alice_in_list, = self.hydrant.hydrate([[struct]])
        self.assertIsInstance(alice_in_list, list)
        alice, = alice_in_list
        self.assertEqual(alice.id, 123)
        self.assertEqual(alice.labels, {"Person"})
        self.assertEqual(set(alice.keys()), {"name"})
        self.assertEqual(alice.get("name"), "Alice")

    def test_can_hydrate_in_dict(self):
        struct = Structure(b'N', 123, ["Person"], {"name": "Alice"})
        alice_in_dict, = self.hydrant.hydrate([{"foo": struct}])
        self.assertIsInstance(alice_in_dict, dict)
        alice = alice_in_dict["foo"]
        self.assertEqual(alice.id, 123)
        self.assertEqual(alice.labels, {"Person"})
        self.assertEqual(set(alice.keys()), {"name"})
        self.assertEqual(alice.get("name"), "Alice")
예제 #3
0
 def setUp(self):
     self.hydrant = PackStreamHydrator(2)