Exemplo n.º 1
0
def test_dobject_dmerge():

    # orginal data
    ASet = dset(t_a)

    ds = ASet([t_a(a=101, b=102, c=103, d=104, e=105),
               t_a(a=201, b=202, c=203, d=204, e=205)])

    t_a1 = t_a._re(_ignore=['c', 'e'])
    A1Set = dset(t_a1)

    ds1 = A1Set(ds)

    dmerge(ds1)

    dbc << "SELECT * FROM t_a"
    ds0 = A1Set(dbc) # original
    ds1 = A1Set(ds0) # to be modified

    ds1 += [t_a1(a=301, b=302, d=304, f=306)] # insert a new item
    ds1[t_a(a=101, b=102)].f = 5555 # update the first item
    del ds1[t_a(a=201, b=202)] # delete the 2nd item

    print('ORIGINAL:', ds0)
    print('MODIFIED:', ds1)

    dmerge(ds1, ds0)
Exemplo n.º 2
0
def test_dset_declaration3():

    class A(dobject):
        a = datt(int)
        b = datt(int)
        __dobject_key__ = [a]

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a)
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)])
    assert s1.a is None

    s1 = BSet(s1, a = 101)
    assert s1.a == 101

    #-------------------------------------------------------------------
    class B(dobject):
        a = datt(int)
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a)
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)], a=101)
    sl = list(s1)
    assert s1.a == 101 and sl[0].a == 101 and sl[1].a == 101

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]
Exemplo n.º 3
0
def test_dset_declaration1():
    class A(dobject):
        a = datt(int)
        b = datt(int)
        __dobject_key__ = [a]

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    # A <>---> B
    BSet = dset(B, _key=A.a)
    assert tuple(BSet.__dobject_key__) == ('a', )
    assert BSet.__dominion_class__ == A
    assert BSet.a != A.a
    assert BSet.a.owner_class == BSet

    BSet = dset(B, _dominion=A, _key=['a'])
    assert tuple(BSet.__dobject_key__) == ('a', )
    assert BSet.__dominion_class__ == A
    assert BSet.a != A.a
    assert BSet.a.owner_class == BSet

    with pytest.raises(ValueError):
        BSet = dset(B, _key=['a'])  # the attribute a is undefined

    BSet = dset(B, _key=dict(a=datt(int)))
    assert tuple(BSet.__dobject_key__) == ('a', )
    assert BSet.__dominion_class__ is None
    assert BSet.a != A.a
    assert BSet.a.owner_class == BSet
Exemplo n.º 4
0
def test_dset_links_1():
    class A(dobject):
        a = datt(int)
        b = datt(int)
        __dobject_key__ = [a]

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a, a='y')  # link
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)], a=101)
    sl = list(s1)
    assert s1.a == 101 and sl[0].y == 101 and sl[1].y == 101

    print(s1)

    #-------------------------------------------------------------------
    class B(dobject):
        a = datt(int)  # the same name with dset key
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a, a='y')  # link
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)], a=101)
    sl = list(s1)
    assert s1.a == 101 and sl[0].y == 101 and sl[1].y == 101
    assert sl[0].a is None and sl[1].a is None

    print(s1)
Exemplo n.º 5
0
def test_dset_declaration3():
    class A(dobject):
        a = datt(int)
        b = datt(int)
        __dobject_key__ = [a]

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a)
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)])
    assert s1.a is None

    s1 = BSet(s1, a=101)
    assert s1.a == 101

    #-------------------------------------------------------------------
    class B(dobject):
        a = datt(int)
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a)
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)], a=101)
    sl = list(s1)
    assert s1.a == 101 and sl[0].a == 101 and sl[1].a == 101

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]
Exemplo n.º 6
0
def test_dobject_dmerge():

    # orginal data
    ASet = dset(t_a)

    ds = ASet([
        t_a(a=101, b=102, c=103, d=104, e=105),
        t_a(a=201, b=202, c=203, d=204, e=205)
    ])

    t_a1 = t_a._re(_ignore=['c', 'e'])
    A1Set = dset(t_a1)

    ds1 = A1Set(ds)

    dmerge(ds1)

    dbc << "SELECT * FROM t_a"
    ds0 = A1Set(dbc)  # original
    ds1 = A1Set(ds0)  # to be modified

    ds1 += [t_a1(a=301, b=302, d=304, f=306)]  # insert a new item
    ds1[t_a(a=101, b=102)].f = 5555  # update the first item
    del ds1[t_a(a=201, b=202)]  # delete the 2nd item

    print('ORIGINAL:', ds0)
    print('MODIFIED:', ds1)

    dmerge(ds1, ds0)
Exemplo n.º 7
0
def test_dset_links_1():

    class A(dobject):
        a = datt(int)
        b = datt(int)
        __dobject_key__ = [a]

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a, a='y') # link
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)], a=101)
    sl = list(s1)
    assert s1.a == 101 and sl[0].y == 101 and sl[1].y == 101

    print(s1)
    #-------------------------------------------------------------------
    class B(dobject):
        a = datt(int) # the same name with dset key
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B, _key=A.a, a='y') # link
    s1 = BSet([B(x=1, y=11), B(x=2, y=22)], a=101)
    sl = list(s1)
    assert s1.a == 101 and sl[0].y == 101 and sl[1].y == 101
    assert sl[0].a is None and sl[1].a is None

    print(s1)
Exemplo n.º 8
0
def test_dset_declaration1():
    class A(dobject):
        a = datt(int)
        b = datt(int)
        __dobject_key__ = [a]

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]


    # A <>---> B
    BSet = dset(B, _key=A.a)
    assert tuple(BSet.__dobject_key__) == ('a',)
    assert BSet.__dominion_class__ == A
    assert BSet.a != A.a
    assert BSet.a.owner_class == BSet

    BSet = dset(B, _dominion=A, _key=['a'])
    assert tuple(BSet.__dobject_key__) == ('a',)
    assert BSet.__dominion_class__ == A
    assert BSet.a != A.a
    assert BSet.a.owner_class == BSet

    with pytest.raises(ValueError):
        BSet = dset(B, _key=['a']) # the attribute a is undefined

    BSet = dset(B, _key=dict(a=datt(int)))
    assert tuple(BSet.__dobject_key__) == ('a',)
    assert BSet.__dominion_class__ is None
    assert BSet.a != A.a
    assert BSet.a.owner_class == BSet
Exemplo n.º 9
0
def test():
    s = seq_po()
    # s.value =100
    print('100, ', bool(s))
    s.value = '100'
    print('200, ', bool(s))
    print('ddd %d' % s)

    mm = mm_po('P003')
    print(mm)

    dbc << 'SELECT %s'
    dbc << (1,)
    dbc << (2,)
    dbc << [(3,), (4,)]

    dbc << ''

    dbc << 'SELECT %s' << (200,)

    dbc << 'select 100'

    s1 =  dset(item_type=mm_po)
    s1.append(mm_po(po_no='P001', po_date=dt.date(2015,7,1), notes='abc'))
    s1.append(mm_po(po_no='P002', po_date=dt.date(2015,7,2), notes='xyz'))
    s1.append(mm_po(po_no='P004', po_date=dt.date(2015,7,4), notes='hij'))
    s1.append(mm_po(po_no='P003', po_date=dt.date(2015,7,3), notes='efg'))

    dmerge(s1, None)

    s2 = s1.copy()
    s2[0].notes = 'abc21'

    s2[2].po_date = dt.date(2015, 6, 2)
    s2[2].notes   = 'abc22'

    dmerge(s2, s1)

    s3 = s2.copy()
    del s3[1]
    dmerge(s3, s2)    

    po_no = 'P001'

    dbc << 'SELECT * FROM mm_po WHERE po_no=%s' 
    po_old = dset(mm_po, dbc << (po_no,))

    po_new = po_old.copy()
    po_new[0].notes = 'test2-123'

    dmerge(po_new, po_old)    
    print(po_new)
Exemplo n.º 10
0
def test_sequence():

    r1 = t_a(b=101)
    r2 = t_a(b=102)
    print('R1: ', r1, '\nR2: ', r2, sep='')
    assert isinstance(r1.a, seq_test) and  isinstance(r2.a, seq_test)
    assert r1.a is not r2.a
    assert r1.a != r2.a

    ASet = dset(t_a)
    s1 = ASet()
    s1 += [r1, r2]
    dmerge(s1)

    print('R1: ', r1, '\nR2: ', r2, sep='')
    assert isinstance(r1.a, seq_test) and  isinstance(r2.a, seq_test)
    assert r1.a is not r2.a
    assert r1.a != r2.a
    assert r1.a.value == 10000 and int(r1.a) == 10000
    assert r2.a.value == 10001 and int(r2.a) == 10001


    dbc << "SELECT * FROM t_a ORDER BY a"
    s1 = ASet(dbc)
    sl = list(s1)
    print(s1)
    assert isinstance(sl[0].a, seq_test)
    assert sl[0].a.value == 10000
    assert sl[0].a == r1.a
Exemplo n.º 11
0
def get_update_labels(repos_sn, label_texts, label_type):

    found_labels = find_labels(repos_sn, label_texts, label_type)

    now = datetime.utcnow();

    LabelSet = dset(ts_label)

    new_labels = LabelSet()
    for text in label_texts:
        if text in found_labels:
            continue

        label = ts_label(repos_sn=repos_sn, label_sn=ts_label_seqno())
        label.label=text
        label.type = label_type
        label.created_ts = now
        label.updated_ts = now

        new_labels._add(label)

    dmerge(new_labels)

    for item in new_labels:
        found_labels[item.label] = item.label_sn

    return found_labels
Exemplo n.º 12
0
async def test_recall2(db, module_dtables):

    ASet = dset(t_b, _key=dict(a=datt(int))) # define a key of dset

    ds1 = ASet(a=1)
    ds1 += [t_b(b=12, c=13, d= 14), t_b(b=22, c=23, d=24)]
    await dmerge(ds1)

    db << 'SELECT 1 as sn FROM t_b'
    await db

    ds2 = ASet(a=2)
    print(333, ds2)
    ds2 += [t_b(b=32, c=33, d= 34), t_b(b=42, c=43, d=44)]
    await dmerge(ds2)

    ds1 = await drecall(ASet(a=1))
    assert len(ds1) == 2

    ds1 += [t_b(b=12, c=113, d=114), t_b(b=62, c=63, d=64)]
    del ds1[t_b(b=22)]
    with pytest.raises(KeyError):
        del ds1[t_b(b=55)]

    ds0 = await drecall(ASet(a=1))

    print("O: ", ds0)
    print("N: ", ds1)

    await dmerge(ds1, ds0)

    ds2 = await drecall(ASet(a=1))
    assert ds2[0].c == ds1[0].c
    assert ds2[1].c == ds1[1].c
Exemplo n.º 13
0
async def test_dmerge(db, module_dtables):
    # schema = DBSchema()
    # schema.add_module(inspect.getmodule(t_a))
    # await schema.drop()
    # await schema.create()

    # orginal data
    ASet = dset(t_a)

    ds = ASet([t_a(a=101, b=102, c=103, d=104, e=105),
               t_a(a=201, b=202, c=203, d=204, e=205)])

    t_a1 = t_a._re(_ignore=['c', 'e'])
    A1Set = dset(t_a1)

    ds1 = A1Set(ds)

    await dmerge(ds1)

    # return

    db << "SELECT * FROM t_a"
    await db

    ds0 = A1Set(db) # original
    ds1 = A1Set(ds0) # to be modified

    ds1 += [t_a1(a=301, b=302, d=304, f=306)] # insert a new item

    ds1[t_a(a=101, b=102)].f = 5555 # update the first item

    del ds1[t_a(a=201, b=202)] # delete the 2nd item

    print('ORIGINAL:', ds0)
    print('MODIFIED:', ds1)

    await dmerge(ds1, ds0)

    SQL("SELECT * FROM t_a ORDER BY a,b") >> db
    ds2 = A1Set(await db)
    print("SELECTED:", ds2)

    assert ds1[0] == ds2[0] and ds1[0].f == ds2[0].f
    assert ds1[1] == ds2[1]
Exemplo n.º 14
0
def case2(page: DPage) -> DSet[test_a] :
    print(3444, page)
    page = DPage(start=3, limit=5, sortable='+sn,-line')

    ASet = dset(test_a, _key=dict(sn=datt(int)))
    ds1 = ASet(sn=101, _page=page)
    for i in range(3,8):
        ds1 += [test_a(line=i, name='L%03d' % i)]

    return ds1
Exemplo n.º 15
0
def case2(page: DPage) -> DSet[test_a]:
    print(3444, page)
    page = DPage(start=3, limit=5, sortable='+sn,-line')

    ASet = dset(test_a, _key=dict(sn=datt(int)))
    ds1 = ASet(sn=101, _page=page)
    for i in range(3, 8):
        ds1 += [test_a(line=i, name='L%03d' % i)]

    return ds1
Exemplo n.º 16
0
async def test_recall_without_dset_key(db, module_dtables):
    ASet = dset(t_b) # define a key of dset

    ds1 = ASet()
    ds1 += [t_b(a=1, b=12, c=13, d= 14), t_b(a=1, b=22, c=23, d=24)]
    ds1 += [t_b(a=1, b=32, c=33, d= 34), t_b(a=1, b=42, c=43, d=44)]
    await dmerge(ds1)

    ds2 = await drecall(ASet())
    assert len(ds2) == 4
    print(ds2)
Exemplo n.º 17
0
def test_recall_without_dset_key():
    ASet = dset(t_b)  # define a key of dset

    ds1 = ASet()
    ds1 += [t_b(a=1, b=12, c=13, d=14), t_b(a=1, b=22, c=23, d=24)]
    ds1 += [t_b(a=1, b=32, c=33, d=34), t_b(a=1, b=42, c=43, d=44)]
    dmerge(ds1)

    ds2 = drecall(ASet())
    assert len(ds2) == 4
    print(ds2)
Exemplo n.º 18
0
def test_dset_declaration2():
    class B(dobject):
        x = datt(int)
        y = datt(int)

    with pytest.raises(TypeError):
        BSet = dset(B)

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = x

    BSet = dset(B)

    s1 = BSet([B(x=1, y=11), B(x=2, y=22)])
    s1 += [B(x=2, y=22)]
    s1 += [B(x=3, y=23)]

    with pytest.raises(ValueError):
        s1 = BSet(s1, e=1)
Exemplo n.º 19
0
def test_recall1():

    ASet = dset(t_b, _key=dict(a=datt(int))) # define a key of dset

    ds1 = ASet(a=11)
    ds1 += [t_b(b=12, c=13, d= 14), t_b(b=22, c=23, d=24)]
    dmerge(ds1)

    r1 = drecall(t_b(a=11, b=12))
    assert r1.a == 11 and r1.b == 12 and r1.c == 13
    r1 = drecall(t_b(a=99, b=12)) # no found and return empty dobject
    assert r1 is not None and not bool(r1)
Exemplo n.º 20
0
def test_recall1():

    ASet = dset(t_b, _key=dict(a=datt(int)))  # define a key of dset

    ds1 = ASet(a=11)
    ds1 += [t_b(b=12, c=13, d=14), t_b(b=22, c=23, d=24)]
    dmerge(ds1)

    r1 = drecall(t_b(a=11, b=12))
    assert r1.a == 11 and r1.b == 12 and r1.c == 13
    r1 = drecall(t_b(a=99, b=12))  # no found and return empty dobject
    assert r1 is not None and not bool(r1)
Exemplo n.º 21
0
async def test_func1(db, event_loop):
    db << """\
    SELECT 1 as name
    """
    async for r in db:
        print(r)

    db << """\
    DROP TABLE IF EXISTS test_123
    """
    await db

    #
    db << """\
    CREATE TABLE IF NOT EXISTS test_123 (
        sn INTEGER,
        name TEXT
    )
    """
    await db

    data = [(1, 'a'), (2, 'b'), (3, 'c')]
    table_name = "test_123"
    for sn, name in data:
        db << f"INSERT INTO {table_name} (sn, name) VALUES ({{sn}}, {{name}})"
        # dbconn << f""
        await db

    data = [{"sn":4, "name":'d'}, {"sn":5, "name":'e'}, {"sn":6, "name":'f'}]
    db << "INSERT INTO test_123 (sn, name) VALUES ({sn}, {name})"
    await db(data)

    db << SQL('SELECT sn, name FROM test_123;')
    async for r in db:
        print(r)

    db << SQL('SELECT sn, name FROM test_123')
    await db
    for r in db:
        print(r)

    class B(dobject):
        sn   = datt(int)
        name = datt(str)
        __dobject_key__ = [sn]

    db << SQL('SELECT sn, name FROM test_123')
    await db

    BSet = dset(B)
    bset = BSet(db)
    print(bset)
Exemplo n.º 22
0
def test_diff():

    from domainics.db.dmerge import _dtable_diff

    # orginal data
    ASet = dset(t_a)
    ds = ASet([
        t_a(a=10010, b=10011, c=10012, d=10013, e=10014),
        t_a(a=10010, b=10021, c=10022, d=10023, e=10024),
    ])

    # constrained information in this domain,
    # reshape t_a to t_a1

    t_a1 = t_a._re(_ignore=('c', 'e'), _name='t_a1')

    A1Set = dset(t_a1)

    ds1 = A1Set(ds)
    ds0 = A1Set()
    inslst, updlst, dellst = _dtable_diff(ds1, ds0)

    assert len(inslst.values) == 2 and len(inslst.pkey_values) == 2
    assert len(updlst.values) == 0 and len(updlst.pkey_values) == 0
    assert len(dellst.pkey_values) == 0

    # print('INS:\n', inslst, '\nUPD:\n', updlst, '\nDEL:\n', dellst)

    ds2 = A1Set(ds1)  # clone it

    ds2[t_a(a=10010, b=10011)].f = 100
    del ds2[t_a(a=10010, b=10021)]

    inslst, updlst, dellst = _dtable_diff(ds2, ds1)
    print('INS:\n', inslst, '\nUPD:\n', updlst, '\nDEL:\n', dellst)

    assert len(inslst.values) == 0 and len(inslst.pkey_values) == 0
    assert len(updlst.values) == 1 and len(updlst.pkey_values) == 1
    assert len(dellst.pkey_values) == 1
Exemplo n.º 23
0
def test_diff():

    from domainics.db.dmerge import _dtable_diff

    # orginal data
    ASet = dset(t_a)
    ds = ASet([
            t_a(a=10010, b=10011, c=10012, d=10013, e=10014),
            t_a(a=10010, b=10021, c=10022, d=10023, e=10024),
            ])

    # constrained information in this domain,
    # reshape t_a to t_a1

    t_a1 = t_a._re(_ignore=('c', 'e'), _name='t_a1')

    A1Set = dset(t_a1)

    ds1 = A1Set(ds)
    ds0 = A1Set()
    inslst, updlst, dellst  = _dtable_diff(ds1, ds0)

    assert len(inslst.values) == 2 and len(inslst.pkey_values) == 2
    assert len(updlst.values) == 0 and len(updlst.pkey_values) == 0
    assert len(dellst.pkey_values) == 0

    # print('INS:\n', inslst, '\nUPD:\n', updlst, '\nDEL:\n', dellst)

    ds2 = A1Set(ds1) # clone it

    ds2[t_a(a=10010, b=10011)].f = 100
    del ds2[t_a(a=10010, b=10021)]

    inslst, updlst, dellst  = _dtable_diff(ds2, ds1)
    print('INS:\n', inslst, '\nUPD:\n', updlst, '\nDEL:\n', dellst)

    assert len(inslst.values) == 0 and len(inslst.pkey_values) == 0
    assert len(updlst.values) == 1 and len(updlst.pkey_values) == 1
    assert len(dellst.pkey_values) == 1
Exemplo n.º 24
0
def test_dset_declaration2():

    class B(dobject):
        x = datt(int)
        y = datt(int)

    with pytest.raises(TypeError):
        BSet = dset(B)

    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = x

    BSet = dset(B)

    s1 = BSet([B(x=1, y=11), B(x=2, y=22)])
    s1 += [B(x=2, y=22)]
    s1 += [B(x=3, y=23)]

    with pytest.raises(ValueError):
        s1 = BSet(s1, e=1)
Exemplo n.º 25
0
def list_repos_briefs(source:str, page: DPage):
    """取得用户信息"""

    user_sn = webreq.principal_id

    dbc << """
    SELECT r.* FROM ts_repos r JOIN ts_repos_user USING (repos_sn)
    WHERE user_sn=%(user_sn)s
    """
    dbc << dict(user_sn=user_sn)
    ReposSet = dset(ts_repos)

    return ReposSet(dbc)
Exemplo n.º 26
0
def test2():
    mm = mm_po(po_no='P003')
    s1 =  dset(item_type=mm_po)
    s1.append(mm_po(po_no='P201'))
    s1.append(mm_po(po_no='P202'))
    s1.append(mm_po(po_no='P203'))

    dmerge(s1)

    s2 = s1.copy()
    s2[0].vendor_sn = vendor_seq()
    s2[1].vendor_sn = vendor_seq()
    dmerge(s2, s1)    
    print(s2)
Exemplo n.º 27
0
def test_dset_clone():
    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B)
    ds1 = BSet([B(x=11, y=12), B(x=21,y=22)])
    ds2 = BSet(ds1)

    ls1 = list(ds1)
    ls2 = list(ds2)

    ls2[0].y = 102

    assert ls1[0].y == 12 and ls2[0].y == 102
Exemplo n.º 28
0
def test_dset_clone():
    class B(dobject):
        x = datt(int)
        y = datt(int)
        __dobject_key__ = [x]

    BSet = dset(B)
    ds1 = BSet([B(x=11, y=12), B(x=21, y=22)])
    ds2 = BSet(ds1)

    ls1 = list(ds1)
    ls2 = list(ds2)

    ls2[0].y = 102

    assert ls1[0].y == 12 and ls2[0].y == 102
Exemplo n.º 29
0
def test_array():

    ASet = dset(t_a)
    s1 = ASet()

    r1 = t_a(a=1)
    s1 += [r1]
    s1[0].b = ['a', 'b']
    assert s1[0].b == ['a', 'b']

    dmerge(s1)

    dbc << "SELECT * FROM t_a ORDER BY a"
    s2 = ASet(dbc)
    assert s2[0].b == ['a', 'b']

    print(s2)
Exemplo n.º 30
0
async def test_array(db, module_dtables):

    ASet = dset(t_a)
    s1 = ASet()

    r1 = t_a(a=1)
    s1 += [r1]
    s1[0].b = ['a', 'b']
    assert s1[0].b == ['a', 'b']

    await dmerge(s1)

    await (db << "SELECT * FROM t_a ORDER BY a")

    s2 = ASet(db)
    assert s2[0].b == ['a', 'b']

    print(s2)
Exemplo n.º 31
0
def test_recall2():

    ASet = dset(t_b, _key=dict(a=datt(int)))  # define a key of dset

    ds1 = ASet(a=1)
    ds1 += [t_b(b=12, c=13, d=14), t_b(b=22, c=23, d=24)]
    dmerge(ds1)

    ds2 = ASet(a=2)
    ds2 += [t_b(b=32, c=33, d=34), t_b(b=42, c=43, d=44)]
    dmerge(ds2)

    ds1 = drecall(ASet(a=1))
    ds1 += [t_b(b=12, c=113, d=114), t_b(b=62, c=63, d=64)]
    del ds1[t_b(b=22)]
    with pytest.raises(KeyError):
        del ds1[t_b(b=55)]
    ds0 = drecall(ASet(a=1))
    print("O: ", ds0)
    print("N: ", ds1)
    dmerge(ds1, ds0)
Exemplo n.º 32
0
def test_recall2():

    ASet = dset(t_b, _key=dict(a=datt(int))) # define a key of dset


    ds1 = ASet(a=1)
    ds1 += [t_b(b=12, c=13, d= 14), t_b(b=22, c=23, d=24)]
    dmerge(ds1)

    ds2 = ASet(a=2)
    ds2 += [t_b(b=32, c=33, d= 34), t_b(b=42, c=43, d=44)]
    dmerge(ds2)

    ds1 = drecall(ASet(a=1))
    ds1 += [t_b(b=12, c=113, d=114), t_b(b=62, c=63, d=64)]
    del ds1[t_b(b=22)]
    with pytest.raises(KeyError):
        del ds1[t_b(b=55)]
    ds0 = drecall(ASet(a=1))
    print("O: ", ds0)
    print("N: ", ds1)
    dmerge(ds1, ds0)
Exemplo n.º 33
0
def test_case2():

    ASet = dset(test_a, _key=dict(sn=datt(int)))
    ds1 = ASet(sn=101)
    for i in range(10):
        ds1 += [test_a(line=i, name='L%03d' % i)]

    ds1 = ASet(sn=202)
    for i in range(10):
        ds1 += [test_a(line=i, name='L%03d' % i)]

    dmerge(ds1)

    page = DPage(start=2, limit=3, sortable='+sn,-line')
    ds1 = ASet(sn=101, _page=page)
    ds2 = drecall(ds1)

    print('ds: ', ds2)

    assert len(ds2) == 3
    assert ds2[test_a(line=7)].line == 7
    assert not ds2[test_a(line=4)]
    assert not ds2[test_a(line=8)]
Exemplo n.º 34
0
def test_case2():

    ASet = dset(test_a, _key=dict(sn=datt(int)))
    ds1 = ASet(sn=101)
    for i in range(10):
        ds1 += [test_a(line=i, name='L%03d' % i)]

    ds1 = ASet(sn=202)
    for i in range(10):
        ds1 += [test_a(line=i, name='L%03d' % i)]

    dmerge(ds1)

    page = DPage(start=2, limit=3, sortable='+sn,-line')
    ds1 = ASet(sn=101, _page=page)
    ds2 = drecall(ds1)

    print('ds: ', ds2)

    assert len(ds2) == 3
    assert ds2[test_a(line=7)].line == 7
    assert not ds2[test_a(line=4)]
    assert not ds2[test_a(line=8)]
Exemplo n.º 35
0
 class A(dobject):
     a_sn = datt(int)
     b = datt(dset(B))
     __dobject_key__ = [a_sn]
Exemplo n.º 36
0
def list_user(page: DPage) -> DSet[UserInfo]:
    """取得用户信息"""

    UserSet = dset(UserInfo)
    users = drecall(UserSet(_page=page))
    return users
Exemplo n.º 37
0
def update_category(repos_sn, json_arg):
    """  """

    now = datetime.utcnow();

    text = json_arg['text'];

    print(repos_sn, text)

    labels = []
    level_1 = ''
    for ln in re.split('[\n\r]+', text):
        m = re.search('(^\s+)', ln)
        sp_num = m.end() if m else 0

        if sp_num > 0:
            labels.append(level_1 + '/' + ln.strip())
        else:
            level_1 = ln.strip()
            labels.append(level_1)


    old_labels = get_repos_categories(repos_sn)

    old_set = set(old_labels.keys())
    new_set = set(labels)

    lbl_com_set = old_set.intersection(new_set)
    lbl_ins_set = new_set.difference(lbl_com_set)


    new_labels = get_update_labels(repos_sn, lbl_ins_set, 'C')

    sn_com_list = set(old_labels[n]['label_sn'] for n in lbl_com_set)
    sn_ins_list = set(int(new_labels[n]) for n in lbl_ins_set)


    orig_categories = drecall(ts_repos_categories(repos_sn=repos_sn))



    categories = ts_repos_categories(repos_sn=repos_sn)
    categories.labels = sorted(int(x) for x in sn_ins_list.union(sn_com_list))
    categories.updated_ts = now

    dmerge(categories, orig_categories)

    ##-----------------------------------------------------------------------
    ## 保留文本指定的顺序

    orders = {}
    for i, lbl in enumerate(labels):
        orders[lbl] = i + 1

    dbc << """\
    WITH s AS (
      SELECT UNNEST(labels) AS label_sn
      FROM ts_repos_categories WHERE repos_sn = %(repos_sn)s
    )
    SELECT t.*
    FROM ts_label t JOIN s USING(label_sn)
    """
    dbc << dict(repos_sn=repos_sn)

    LabelSet = dset(ts_label)

    old_label_set = LabelSet(dbc)

    label_set = LabelSet()
    for r in old_label_set:
        r = ts_label(r)
        r.props = copy.deepcopy(r.props) # 需要复制,否则修改的是旧的
        label_set._add(r)

    for r in label_set:
        ordnum = orders[r.label]
        if r.props:
            if 'order' in r.props and r.props['order'] == ordnum:
                continue

            r.props['order'] = ordnum
        else:
            pass
            r.props = {'order': ordnum}
        r.updated_ts = now

    dmerge(label_set, old_label_set)
Exemplo n.º 38
0
 class Bill(dobject):
     sn = datt(int)
     __dobject_key__ = [sn]
     items = datt(dset(Item, sn='bill_sn'), doc="")
Exemplo n.º 39
0
    class A(dobject):
        a = datt(int)

        x = datt(dset(B))

        __dobject_key__ = [a]