Esempio n. 1
0
    def test_list_records(self):
        """Test that RecordList works"""
        class SingleThing(Record):
            name = Property()

        class ManyThingsRecord(RecordList):
            itemtype = SingleThing

        # note: must pass pre-coerced members to constructor.
        mtr = ManyThingsRecord(
            (SingleThing(name="bert"), SingleThing(name="phil")))
        self.assertEqual(record_id(mtr[0]), ("bert", ))
        self.assertEqual(record_id(mtr), (("bert", ), ("phil", )))

        self.assertTrue(mtr.__getitem__)
        self.assertIsInstance(mtr, ManyThingsRecord)

        # test construction from generators
        def generator(seq):
            for x in seq:
                yield x

        ManyThingsRecord(generator(mtr))

        # ...iterators...
        ManyThingsRecord(mtr)
Esempio n. 2
0
    def test_list_records(self):
        """Test that RecordList works"""
        class SingleThing(Record):
            name = Property()

        class ManyThingsRecord(RecordList):
            itemtype = SingleThing

        # note: must pass pre-coerced members to constructor.
        mtr = ManyThingsRecord(
            (SingleThing(name="bert"), SingleThing(name="phil"))
        )
        self.assertEqual(record_id(mtr[0]), ("bert",))
        self.assertEqual(record_id(mtr), (("bert",), ("phil",)))

        self.assertTrue(mtr.__getitem__)
        self.assertIsInstance(mtr, ManyThingsRecord)

        # test construction from generators
        def generator(seq):
            for x in seq:
                yield x

        mtr2 = ManyThingsRecord(generator(mtr))

        # ...iterators...
        mtr2 = ManyThingsRecord(mtr)
Esempio n. 3
0
 def __pk__(self):
     """This property returns the "primary key" for this object.  This is
     similar to what is used when comparing Collections via
     :py:mod:`normalize.diff`, and is used for stringification and for the
     ``id()`` built-in.
     """
     return record_id(self, type(self))
Esempio n. 4
0
 def __pk__(self):
     """This property returns the "primary key" for this object.  This is
     similar to what is used when comparing Collections via
     :py:mod:`normalize.diff`, and is used for stringification and for the
     ``id()`` built-in.
     """
     return record_id(self, type(self))