From 25afc7da0db43754f6b4373a10b66551dd3cbd57 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 3 Sep 2015 23:06:18 +0100 Subject: [PATCH] tests: Add tests to improve coverage of objstr.c. --- tests/basics/builtin_ord.py | 6 ++++++ tests/basics/bytes_construct.py | 12 ++++++++++++ tests/basics/setattr1.py | 5 +++++ tests/basics/string1.py | 4 ++++ tests/basics/string_compare.py | 5 +++++ tests/basics/string_format.py | 6 ++++++ tests/basics/struct1.py | 6 ++++++ tests/extmod/ujson_dumps_extra.py | 5 +++++ tests/extmod/ujson_dumps_extra.py.exp | 1 + tests/misc/non_compliant.py | 18 ++++++++++++++++++ tests/misc/non_compliant.py.exp | 3 +++ tests/unix/extra_coverage.py.exp | 2 ++ unix/coverage.c | 8 ++++++++ 13 files changed, 81 insertions(+) create mode 100644 tests/extmod/ujson_dumps_extra.py create mode 100644 tests/extmod/ujson_dumps_extra.py.exp diff --git a/tests/basics/builtin_ord.py b/tests/basics/builtin_ord.py index 66e56e5c6f..1556970ee3 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 e43c8179fc..59e02f063c 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 acc3299119..9693aca819 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 b8ca15c344..b3abfb9c60 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 740e1959c8..f011ed3630 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 b0e49f530a..d8724c9474 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 87e2f07026..686251c446 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -52,3 +52,9 @@ print(struct.unpack("