From 31fe40991ea6e289bc3ea57cd14c95a1fc478c68 Mon Sep 17 00:00:00 2001 From: Tibor Arpas Date: Thu, 4 Jan 2018 09:21:09 +0100 Subject: [PATCH] re #14, exception referring to the bug in github. --- exampleproject/tests/print1250r.py | 3 +++ exampleproject/tests/test_a.py | 2 -- exampleproject/tests/test_non_utf_crash.py | 2 ++ testmon/testmon_core.py | 9 +++++++-- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 exampleproject/tests/print1250r.py create mode 100644 exampleproject/tests/test_non_utf_crash.py diff --git a/exampleproject/tests/print1250r.py b/exampleproject/tests/print1250r.py new file mode 100644 index 0000000..0f3238d --- /dev/null +++ b/exampleproject/tests/print1250r.py @@ -0,0 +1,3 @@ +# -- coding:cp1250 -- + +print("š") diff --git a/exampleproject/tests/test_a.py b/exampleproject/tests/test_a.py index 2c39e71..b760e48 100644 --- a/exampleproject/tests/test_a.py +++ b/exampleproject/tests/test_a.py @@ -18,8 +18,6 @@ def test_add_and_multiply(): def test_error3(): pass - pass - raise Exception('error1') @pytest.mark.xfail(True, reason="Division by zero not implemented yet.") diff --git a/exampleproject/tests/test_non_utf_crash.py b/exampleproject/tests/test_non_utf_crash.py new file mode 100644 index 0000000..294d600 --- /dev/null +++ b/exampleproject/tests/test_non_utf_crash.py @@ -0,0 +1,2 @@ +def test_basic(): + import print1250r diff --git a/testmon/testmon_core.py b/testmon/testmon_core.py index f2e4a15..ba0ca4c 100644 --- a/testmon/testmon_core.py +++ b/testmon/testmon_core.py @@ -150,8 +150,13 @@ def get_variant_inifile(inifile): def read_file_with_checksum(absfilename): hasher = hashlib.sha1() - with open(absfilename) as afile: - source = afile.read() + try: + with open(absfilename) as afile: + source = afile.read() + except UnicodeDecodeError: + raise Exception("""You are hitting https://github.com/tarpas/pytest-testmon/issues/14""" + """ when reading {}""".format(absfilename)) + hasher.update(encode(source)) return source, hasher.hexdigest()