def test_TaggedList_init_two_values_second_with_key(): t = TaggedList([11, ('v2', 22)]) assert t.astuples() == [(None, 11), ('v2', 22)] assert len(t) == 2 assert t[0] == 11 assert t[1] == 22 assert t['v2'] == 22
def test_tagged_lists(): """ Tests 'tagged' lists, i.e. lists which allow to address their items via name, not only via index. Those R lists are translated into 'TaggedList'-objects in Python. """ res = conn.r('list(husband="otto")') assert res == TaggedList([("husband", "otto")]) # a mixed list, where the 2nd item has no tag: exp_res = TaggedList([("n", "Fred"), ("v", 2.0), ("c_ages", numpy.array([1.0, 2.0]))]) res = conn.r('list(n="Fred", v=2, c_ages=c(1, 2))') # do string comparison because of complex nested data! assert repr(res) == repr(exp_res) # test via call to ident function with single argument: # do string comparison because of complex nested data! assert repr(conn.r.ident(exp_res)) == repr(exp_res)
def test_TaggedList_init_emtpy(): t = TaggedList() assert t.astuples() == [] assert len(t) == 0
def test_TaggedList_insert_with_key(): t = TaggedList([11, ('v2', 22)]) t.insert(0, x=1) assert len(t) == 3 assert t.values == [1, 11, 22] assert t[0] == t['x'] == 1
def test_TaggedList_insert(): t = TaggedList([11, ('v2', 22)]) t.insert(0, 1) assert len(t) == 3 assert t.values == [1, 11, 22]
def test_TaggedList_append_with_key(): t = TaggedList([11, ('v2', 22)]) t.append(v3=33) assert len(t) == 3 assert t.values == [11, 22, 33] assert t['v3'] == 33
def test_TaggedList_append(): t = TaggedList([11, ('v2', 22)]) t.append(33) assert len(t) == 3 assert t.values == [11, 22, 33]
def test_TaggedList_init_one_value_with_key(): t = TaggedList([('v1', 11)]) assert t.astuples() == [('v1', 11)] assert len(t) == 1 assert t[0] == 11 assert t['v1'] == 11
def test_TaggedList_init_one_value(): t = TaggedList([11]) assert t.astuples() == [(None, 11)] assert len(t) == 1 assert t[0] == 11