Exemplo n.º 1
0
class Node(dr.Ann):
  label = dr.Field()
  parent = dr.SelfPointer()
  other = dr.Pointer('Node', store='nodes2')

  def __repr__(self):
    return 'Node({0})'.format(self.label)

  class Meta:
    name = 'Node'
Exemplo n.º 2
0
class MyAnnot(dr.Ann):
    field = dr.Field()
    children = dr.Pointers('MyAnnot')
    child = dr.Pointer('MyAnnot')

    def __repr__(self):
        return '{}(field={}, children={}, child={})'.format(
            self.__class__.__name__, self.field, self.children, self.child)

    class Meta:
        name = 'MyAnnot'
Exemplo n.º 3
0
    def test_pointer(self):
        A = dr.make_ann('A',
                        'x',
                        'y',
                        z=dr.SelfPointer(),
                        __module__='SerialTest.test_pointer')
        B = dr.make_ann('B',
                        p=dr.Pointer(A),
                        __module__='SerialTest.test_pointer')

        class Doc(dr.Doc):
            sa = dr.Store(A)
            sb = dr.Store(B)

            class Meta:
                name = 'SerialTest.test_pointer.Doc'

        d = Doc()
        a1 = d.sa.create(x=1, y=2, z=None)
        a2 = d.sa.create(x=11, y=21, z=a1)
        d.sb.create(p=None)
        d.sb.create(p=a2)

        d = write_read(d, Doc)

        self.assertEqual(len(d.sa), 2)
        self.assertEqual(len(d.sb), 2)
        a1, a2 = d.sa
        b1, b2 = d.sb

        self.assertEqual(a1.x, 1)
        self.assertEqual(a1.y, 2)
        self.assertIsNone(a1.z)

        self.assertEqual(a2.x, 11)
        self.assertEqual(a2.y, 21)
        self.assertIs(a2.z, a1)

        self.assertIsNone(b1.p)

        self.assertIs(b2.p, a2)
Exemplo n.º 4
0
class Doc(dr.Doc):
    foos = dr.Store(Foo)
    wrong_foos = dr.Store(Foo)
    bars = dr.Store(Bar)
    favourite = dr.Pointer(Foo, store='foos')
Exemplo n.º 5
0
class Z(dr.Ann):
    p = dr.Pointer(A, serial='zp')
    value = dr.Field()

    class Meta:
        serial = 'writer.Z'
Exemplo n.º 6
0
class Y(dr.Ann):
    p = dr.Pointer(A)

    class Meta:
        serial = 'writer.Y'
Exemplo n.º 7
0
class DocWithAnnotsAndPointer(dr.Doc):
    annots = dr.Store(Annot)
    special_annot = dr.Pointer(Annot)
class Foo(dr.Ann):
  label = dr.Field()
  other = dr.Pointer('Foo')

  class Meta:
    name = 'Foo'