def test_load_card_with_fix_buf(page: Page): page['card1'] = dict(data=data(fields=sample_fields, rows=[[1, 2, 3]])) page.save() expect( page.load(), make_page(card1=make_card( data=make_fix_buf(fields=sample_fields, data=[[1, 2, 3]]))))
def test_new_card_with_cyc_buf(page: Page): page['card1'] = dict(data=data(fields=sample_fields, size=-3)) page.save() expect( page.load(), make_page(card1=make_card( data=make_cyc_buf(fields=sample_fields, data=[None] * 3, i=0))))
def test_new_card_with_map_buf(page: Page): page['card1'] = dict(data=data(fields=sample_fields)) page.save() expect( page.load(), make_page(card1=make_card( data=make_map_buf(fields=sample_fields, data={}))))
def test_fix_buf_init(page: Page): c = page.add('card1', dict(data=data(fields=sample_fields, size=3))) c.data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] page.save() expect( page.load(), make_page(card1=make_card(data=make_fix_buf( fields=sample_fields, data=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], ))))
def test_cyc_buf_init(page: Page): c = page.add('card1', dict(data=data(fields=sample_fields, size=-3))) c.data = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] # insert 4 instead of 3; should circle back page.save() expect( page.load(), make_page(card1=make_card(data=make_cyc_buf( fields=sample_fields, data=[[10, 11, 12], [4, 5, 6], [7, 8, 9]], i=1, ))))
def test_map_buf_init(page: Page): c = page.add('card1', dict(data=data(fields=sample_fields))) c.data = dict(foo=[1, 2, 3], bar=[4, 5, 6], baz=[7, 8, 9]) page.save() expect( page.load(), make_page(card1=make_card(data=make_map_buf(fields=sample_fields, data=dict( foo=[1, 2, 3], bar=[4, 5, 6], baz=[7, 8, 9], )))))
def test_array_prop_set_deep(page: Page): page['card1'] = dict(a=[[[[42]]]]) page.save() c = page['card1'] c.a[0][0][0][0] = 420 page.save() expect(page.load(), make_page(card1=make_card(a=[[[[420]]]]))) c.a[0][0][0] = [42, 420] page.save() expect(page.load(), make_page(card1=make_card(a=[[[[42, 420]]]])))
def test_map_prop_set(page: Page): page['card1'] = dict(m=dict(s="foo")) page.save() c = page['card1'] c.m.s = "bar" page.save() expect(page.load(), make_page(card1=make_card(m=dict(s="bar")))) c.m.s = None c.m.s2 = "bar" page.save() expect(page.load(), make_page(card1=make_card(m=dict(s2="bar"))))
def test_map_prop_set_deep(page: Page): page['card1'] = dict(m=dict(m=dict(m=dict(s="foo")))) page.save() c = page['card1'] c.m.m.m.s = "bar" page.save() expect(page.load(), make_page(card1=make_card(m=dict(m=dict(m=dict(s="bar")))))) c.m.m.m = dict(answer=42) page.save() expect(page.load(), make_page(card1=make_card(m=dict(m=dict(m=dict(answer=42))))))
def test_array_prop_set(page: Page): page['card1'] = dict(a=[1, 2, 3]) page.save() c = page['card1'] c.a[2] = 33 page.save() expect(page.load(), make_page(card1=make_card(a=[1, 2, 33]))) c.a[33] = 100 # index out of bounds expect(page.load(), make_page(card1=make_card(a=[1, 2, 33])))
def test_prop_set(page: Page): page['card1'] = dict() page.save() c = page['card1'] c.s = "foo" c.i = 42 c.f = 4.2 c.bt = True c.bf = False page.save() expect(page.load(), make_page(card1=make_card(s="foo", i=42, f=4.2, bt=True, bf=False))) c.s = "bar" c.i = 420 c.f = 40.2 page.save() expect( page.load(), make_page(card1=make_card(s="bar", i=420, f=40.2, bt=True, bf=False)))
def test_cyc_buf_write(page: Page): c = page.add('card1', dict(data=data(fields=sample_fields, size=-3))) c.data[0] = [1, 2, 3] c.data[1] = [4, 5, 6] c.data[2] = [7, 8, 9] c.data[100] = [10, 11, 12] # keys don't matter c.data[101] = [13, 14, 15] # keys don't matter page.save() expect( page.load(), make_page(card1=make_card(data=make_cyc_buf( fields=sample_fields, data=[[10, 11, 12], [13, 14, 15], [7, 8, 9]], i=2, )))) c.data[2][1] = 42 page.save() expect( page.load(), make_page(card1=make_card(data=make_cyc_buf( fields=sample_fields, data=[[10, 11, 12], [13, 14, 15], [7, 42, 9]], i=2, )))) c.data[2][1] = [41, 42, 43] page.save() expect( page.load(), make_page(card1=make_card(data=make_cyc_buf( fields=sample_fields, data=[[10, 11, 12], [13, 14, 15], [7, [41, 42, 43], 9]], i=2, )))) c.data[2][1][1] = 999 page.save() expect( page.load(), make_page(card1=make_card(data=make_cyc_buf( fields=sample_fields, data=[[10, 11, 12], [13, 14, 15], [7, [41, 999, 43], 9]], i=2, ))))
def test_fix_buf_write(page: Page): c = page.add('card1', dict(data=data(fields=sample_fields, size=3))) c.data[0] = [1, 2, 3] c.data[1] = [4, 5, 6] c.data[2] = [7, 8, 9] page.save() expect( page.load(), make_page(card1=make_card(data=make_fix_buf( fields=sample_fields, data=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], )))) c.data[2][1] = 42 page.save() expect( page.load(), make_page(card1=make_card(data=make_fix_buf( fields=sample_fields, data=[[1, 2, 3], [4, 5, 6], [7, 42, 9]], )))) c.data[2][1] = [41, 42, 43] page.save() expect( page.load(), make_page(card1=make_card(data=make_fix_buf( fields=sample_fields, data=[[1, 2, 3], [4, 5, 6], [7, [41, 42, 43], 9]], )))) c.data[2][1][1] = 999 page.save() expect( page.load(), make_page(card1=make_card(data=make_fix_buf( fields=sample_fields, data=[[1, 2, 3], [4, 5, 6], [7, [41, 999, 43], 9]], ))))
def test_map_buf_write(page: Page): c = page.add('card1', dict(data=data(fields=sample_fields))) c.data.foo = [1, 2, 3] c.data.bar = [4, 5, 6] c.data.baz = [7, 8, 9] page.save() expect( page.load(), make_page(card1=make_card(data=make_map_buf(fields=sample_fields, data=dict( foo=[1, 2, 3], bar=[4, 5, 6], baz=[7, 8, 9], ))))) c.data.baz[1] = 42 page.save() expect( page.load(), make_page(card1=make_card(data=make_map_buf(fields=sample_fields, data=dict( foo=[1, 2, 3], bar=[4, 5, 6], baz=[7, 42, 9], ))))) c.data.baz[1] = [41, 42, 43] page.save() expect( page.load(), make_page(card1=make_card( data=make_map_buf(fields=sample_fields, data=dict( foo=[1, 2, 3], bar=[4, 5, 6], baz=[7, [41, 42, 43], 9], ))))) c.data.baz[1][1] = 999 page.save() expect( page.load(), make_page(card1=make_card( data=make_map_buf(fields=sample_fields, data=dict( foo=[1, 2, 3], bar=[4, 5, 6], baz=[7, [41, 999, 43], 9], )))))
def test_new_card_with_props(page: Page): page['card1'] = dict(s="foo", i=42, f=4.2, bt=True, bf=False, n=None) page.save() expect(page.load(), make_page(card1=make_card(s="foo", i=42, f=4.2, bt=True, bf=False)))
def test_new_empty_card(page: Page): page['card1'] = dict() page.save() expect(page.load(), make_page(card1=make_card()))