diff --git a/tests/basics/builtin_ord.py b/tests/basics/builtin_ord.py index 66e56e5c6fad9962a0809c21a4e8707132155b73..1556970ee3f945d70aad6cd8cebb04bcebf2ce38 100644 --- a/tests/basics/builtin_ord.py +++ b/tests/basics/builtin_ord.py @@ -20,3 +20,9 @@ try: ord(b'') except TypeError: print("TypeError") + +# argument must be a string +try: + ord(1) +except TypeError: + print('TypeError') diff --git a/tests/basics/bytes_construct.py b/tests/basics/bytes_construct.py index e43c8179fc0b07a0060e28cccefa3e4ea0106629..59e02f063c98706a43b72965b42c939bc1049416 100644 --- a/tests/basics/bytes_construct.py +++ b/tests/basics/bytes_construct.py @@ -14,6 +14,18 @@ print(bytes(array('h', [0x101, 0x202]))) # long ints print(ord(bytes([14953042807679334000 & 0xff]))) +# constructor value out of range +try: + bytes([-1]) +except ValueError: + print('ValueError') + +# constructor value out of range +try: + bytes([256]) +except ValueError: + print('ValueError') + # error in construction try: a = bytes([1, 2, 3], 1) diff --git a/tests/basics/setattr1.py b/tests/basics/setattr1.py index acc3299119aaff4fff12a855b3b441deb7fb08af..9693aca8196ad2a812d51f66a0f6ed03b0f9d9bf 100644 --- a/tests/basics/setattr1.py +++ b/tests/basics/setattr1.py @@ -11,3 +11,8 @@ setattr(a, "var", 123) setattr(a, "var2", 56) print(a.var) print(a.var2) + +try: + setattr(a, b'var3', 1) +except TypeError: + print('TypeError') diff --git a/tests/basics/string1.py b/tests/basics/string1.py index b8ca15c3445b52aba729aa4b5e37183fe6bb8fc5..b3abfb9c608bdfb03384577abd93e32fd7f98403 100644 --- a/tests/basics/string1.py +++ b/tests/basics/string1.py @@ -24,6 +24,10 @@ try: '123' * '1' except TypeError: print('TypeError') +try: + '123' + 1 +except TypeError: + print('TypeError') # subscription print('abc'[1]) diff --git a/tests/basics/string_compare.py b/tests/basics/string_compare.py index 740e1959c8a87adf89f7971b3f78a3cccbf77ab2..f011ed363068a51c499d538e7a38fed140471745 100644 --- a/tests/basics/string_compare.py +++ b/tests/basics/string_compare.py @@ -48,3 +48,8 @@ print("1" <= "10") print("1" <= "1/") print("10" <= "1") print("1/" <= "1") + +# this tests an internal string that doesn't have a hash with a string +# that does have a hash, but the lengths of the two strings are different +import sys +print(sys.version == 'a long string that has a hash') diff --git a/tests/basics/string_format.py b/tests/basics/string_format.py index b0e49f530a93238a0679e163d4ee2f4783eb6719..d8724c947488da729aa3e0f49c3c6f086bbc8672 100644 --- a/tests/basics/string_format.py +++ b/tests/basics/string_format.py @@ -207,3 +207,9 @@ try: '{:*"1"}'.format('zz') except ValueError: print('ValueError') + +# unknown format code for str arg +try: + '{:X}'.format('zz') +except ValueError: + print('ValueError') diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index 87e2f07026f95ad433c2573a980495426b883256..686251c446785190f4503eb537d309b9c243c3a5 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -52,3 +52,9 @@ print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff")) # network byte order print(struct.pack('!i', 123)) + +# first arg must be a string +try: + struct.pack(1, 2) +except TypeError: + print('TypeError') diff --git a/tests/extmod/ujson_dumps_extra.py b/tests/extmod/ujson_dumps_extra.py new file mode 100644 index 0000000000000000000000000000000000000000..0e593c3e93338ef6a4f4791e2250c1b88a6416b4 --- /dev/null +++ b/tests/extmod/ujson_dumps_extra.py @@ -0,0 +1,5 @@ +# test uPy ujson behaviour that's not valid in CPy + +import ujson + +print(ujson.dumps(b'1234')) diff --git a/tests/extmod/ujson_dumps_extra.py.exp b/tests/extmod/ujson_dumps_extra.py.exp new file mode 100644 index 0000000000000000000000000000000000000000..51712af1b5b1c62b0c80b8c26dbe8b9a042aa5ff --- /dev/null +++ b/tests/extmod/ujson_dumps_extra.py.exp @@ -0,0 +1 @@ +"1234" diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py index 79f1e70c883723a624ef2bc15285e0147ce92a88..09abac238858a03800095b5ee7ca7f9a85f26004 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -40,8 +40,26 @@ try: except NotImplementedError: print('NotImplementedError') +# str(...) with keywords not implemented +try: + str(b'abc', encoding='utf8') +except NotImplementedError: + print('NotImplementedError') + # str.rsplit(None, n) not implemented try: 'a a a'.rsplit(None, 1) except NotImplementedError: print('NotImplementedError') + +# bytes(...) with keywords not implemented +try: + bytes('abc', encoding='utf8') +except NotImplementedError: + print('NotImplementedError') + +# bytes subscr with step!=1 not implemented +try: + b'123'[0:3:2] +except NotImplementedError: + print('NotImplementedError') diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp index 3790f4f346a9d518e8f0fcac0906bd37cb0c97d1..9278034aa42e104b50bef4187f2fc3f1ed56544d 100644 --- a/tests/misc/non_compliant.py.exp +++ b/tests/misc/non_compliant.py.exp @@ -5,3 +5,6 @@ True TypeError, ValueError NotImplementedError NotImplementedError +NotImplementedError +NotImplementedError +NotImplementedError diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 651a47819c30723c4cbe708e3ab65e4d80a02219..00ddf0daf265f4c2e15c0a8d5220bc4cdb304d30 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -25,3 +25,5 @@ stderr exc_info print_exception ementation # attrtuple (start=1, stop=2, step=3) +# str +1 diff --git a/unix/coverage.c b/unix/coverage.c index eabd0097d723de420a6933e07e5adcefa7c5085d..1f52d9cf82758901b59e19f14cffeca453b6b02f 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -75,6 +75,14 @@ STATIC mp_obj_t extra_coverage(void) { printf("\n"); } + // str + { + printf("# str\n"); + + // intern string + printf("%d\n", MP_OBJ_IS_QSTR(mp_obj_str_intern(mp_obj_new_str("intern me", 9, false)))); + } + return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(extra_coverage_obj, extra_coverage);