def test_string_literals(): assert model.eval('"hi"') == 'hi' assert model.eval("'hello'") == 'hello' assert model.eval("'how\\nare\\nyou'") == 'how\nare\nyou' assert model.eval("'\\0\\x00\\377'") == '\0\x00\377' assert model.eval("'\\r\\t\\n'") == '\r\t\n' assert model.eval('"\\r\\t\\n"') == '\r\t\n' assert model.eval("'multi'' ' 'part' ' ''string'") == 'multi part string' # create a concatenation of lines as literals lorem_ipsum_quoted = "'" + LOREM_IPSUM.replace('\n', "\\n'\n '") + "'" assert model.eval(lorem_ipsum_quoted) == LOREM_IPSUM with pytest.raises(ValueError): model.eval('hello')
def test_leveldb_log_empty(spec_log, data_log_empty): dtree = model.DataTree(data_log_empty, spec_log) assert model.make_python_object(dtree.head_blocks) == [] assert model.make_python_object(dtree.tail_block.records) == [] assert len(dtree.head_blocks) == 0 assert len(dtree.tail_block.records) == 0 assert model.eval('sizeof(head_blocks)', dtree) == 0 assert model.eval('sizeof(tail_block.records)', dtree) == 0 with pytest.raises(IndexError): dtree.tail_block.records[0] with pytest.raises(ValueError): model.eval('tail_block.records[0]', dtree)
def test_links_1(params_links_1): params = params_links_1 dtree = params['dtree'] for i in range(3): assert dtree.typed[i] == i + 1 assert dtree.untyped[i]['?value'] == i + 1 assert model.eval('untyped[{0}].?value'.format(i), dtree) == i + 1
def test_links_2(params_links_2): params = params_links_2 dtree = params['dtree'] for i in range(3): assert dtree.typed[i] == i + 1 assert dtree['?untyped_as_typed'][i] == i + 1 assert model.eval('?untyped_as_typed[{0}]'.format(i), dtree) == i + 1
def test_links_3(params_links_3): params = params_links_3 dtree = params['dtree'] for i in range(3): assert dtree.typed[i] == i + 1 assert dtree['?numbers'][i].value == i + 1 assert model.eval('?numbers[{0}].value'.format(i), dtree) == i + 1
def test_leveldb_log_small(spec_log, data_log_small): dtree = model.DataTree(data_log_small, spec_log) assert model.make_python_object(dtree.head_blocks) == [] records = dtree.tail_block.records assert len(records) == 2 assert records[0].checksum == 0xC227CC1B assert records[0].length == 33 assert records[0].rtype == 1 assert len(records[0].data) == 33 assert model.eval('sizeof(tail_block.records[0])', dtree) == 40 assert records[1].checksum == 0x6EC2C495 assert records[1].length == 39 assert records[1].rtype == 1 assert len(records[1].data) == 39 assert model.eval('sizeof(tail_block.records[1])', dtree) == 46 assert model.eval('sizeof(tail_block.records)', dtree) == 86 assert model.eval('sizeof(tail_block)', dtree) == 86 with pytest.raises(IndexError): dummy = records[2] with pytest.raises(ValueError): model.eval('tail_block.records[2]', dtree)
def test_leveldb_log_multiblock(spec_log, data_log_multiblock): dtree = model.DataTree(data_log_multiblock, spec_log) assert len(dtree.head_blocks) == 1 assert len(dtree.head_blocks[0].records) == 762 assert len(dtree.tail_block.records) == 3 assert model.eval('sizeof(head_blocks)', dtree) == 32768 assert model.eval('sizeof(head_blocks[0])', dtree) == 32768 assert model.eval('sizeof(head_blocks[0].records)', dtree) == 32766 assert model.eval('sizeof(head_blocks[0].trailer)', dtree) == 2 assert model.make_python_object(model.eval('head_blocks[0].trailer', dtree)) == '\x00\x00' assert model.eval('sizeof(tail_block.records)', dtree) == 43 * 3 records = dtree.head_blocks[0].records dummy = records[761] with pytest.raises(IndexError): dummy = records[762]
def test_integer_literals(): assert model.eval('0') == 0 assert model.eval('1') == 1 assert model.eval('123456789') == 123456789 assert model.eval('42000000000000') == 42000000000000 assert model.eval('07') == 7 assert model.eval('01234567') == 01234567 assert model.eval('0xdeadbeef') == 0xdeadbeef assert model.eval('0xdeadbeefbadf00d') == 0xdeadbeefbadf00d with pytest.raises(ValueError): model.eval('0abc') with pytest.raises(ValueError): model.eval('0xffeeg') with pytest.raises(ValueError): model.eval('42a') with pytest.raises(ValueError): model.eval('42a') with pytest.raises(ValueError): model.eval('08')