Skip to content

Commit e480c07

Browse files
committed
add tests
1 parent 4eedac6 commit e480c07

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_map.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ def test_map2():
5858
items0 = [0, 1, 2, 3, 4]
5959
items1 = [5, 6, 7, 8, 9]
6060
assert list(map(lambda x, y: x * y, items0, items1)) == [0, 6, 14, 24, 36]
61+
62+
63+
def test_map_contains():
64+
assert 1 in map(lambda s: s, [1])
65+
assert 2 not in map(lambda s: s, [1])
66+
67+
class X():
68+
def __iter__(self):
69+
return self
70+
71+
def __next__(self):
72+
i = getattr(self, "i", 0)
73+
if i == 1:
74+
raise StopIteration
75+
else:
76+
self.i = i + 1
77+
return i
78+
79+
# the below checks that __contains__ consumes the iterator
80+
m = map(lambda s: s, X())
81+
assert 0 in m
82+
assert 0 not in m

graalpython/com.oracle.graal.python.test/src/tests/test_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ def test_lambda_no_args_with_nested_lambdas():
8484
except Exception as e:
8585
no_err = False
8686
assert no_err
87+
88+
89+
def test_byte_numeric_escapes():
90+
assert eval('b"PK\\005\\006\\00\\11\\22\\08"') == b'PK\x05\x06\x00\t\x12\x008'

graalpython/com.oracle.graal.python.test/src/tests/test_string.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_find():
5353
assert s.find('cau', MyIndexable(5), None) == 5
5454
assert s.find('cau', MyIndexable(5), MyIndexable(8)) == 5
5555
assert s.find('cau', None, MyIndexable(8)) == 5
56-
56+
5757

5858
def test_rfind():
5959
assert "test string test".rfind("test") == 12
@@ -749,7 +749,7 @@ def test_zfill(self):
749749
self.checkequal('0034', '34', 'zfill', 4)
750750

751751
self.checkraises(TypeError, '123', 'zfill')
752-
752+
753753
def test_zfill_specialization(self):
754754
self.checkequal('123', '123', 'zfill', True)
755755
self.checkequal('0123', '123', 'zfill', MyIndexable(4))
@@ -880,7 +880,7 @@ def test_count(self):
880880
if rem or r1 != r2:
881881
self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
882882
self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))
883-
883+
884884

885885
def test_same_id():
886886
empty_ids = set([id(str()) for i in range(100)])
@@ -889,3 +889,21 @@ def test_same_id():
889889
assert len(empty_ids) == 1
890890
empty_ids = set([id(u'') for i in range(100)])
891891
assert len(empty_ids) == 1
892+
893+
894+
def test_translate():
895+
assert "abc".translate({ord("a"): "b"}) == "bbc"
896+
assert "abc".translate({ord("a"): "xxx"}) == "xxxbc"
897+
assert "abc".translate({ord("a"): ""}) == "bc"
898+
try:
899+
"abc".translate({ord("a"): 8**63})
900+
except ValueError as e:
901+
assert "mapping must be in range" in str(e)
902+
else:
903+
assert False, "should raise"
904+
905+
906+
def test_splitlines():
907+
assert len(str.splitlines("\n\n")) == 2
908+
assert len(str.splitlines("\n")) == 1
909+
assert len(str.splitlines("a\nb")) == 2

graalpython/com.oracle.graal.python.test/src/tests/test_vars.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,16 @@ def test_vars():
7474
assert_raises(TypeError, vars, 42, 42)
7575
assert_raises(TypeError, vars, 42)
7676
assert vars(C_get_vars()) == {'a': 2}
77+
78+
79+
def test_vars_update():
80+
class X():
81+
pass
82+
83+
x = X()
84+
vars(x).update({"args": 42})
85+
assert vars(x)["args"] == 42
86+
assert x.__dict__["args"] == 42
87+
88+
vars().update({"arg": 12})
89+
assert locals()["arg"] == 12

0 commit comments

Comments
 (0)