From 95e8e2f2ce9d384dc52978c709ddf7c05812a9bb Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 14 Oct 2019 11:04:55 +0900 Subject: [PATCH] Rename some test filenames by convention --- .../{test_async_stuff.py => async_stuff.py} | 0 tests/snippets/builtin_complex.py | 23 ++++++++++++++++++- .../{test_exec.py => builtin_exec.py} | 0 tests/snippets/math_basics.py | 19 +++++++++++++++ tests/snippets/set.py | 20 ++++++++++++++++ tests/snippets/{test_abc.py => stdlib_abc.py} | 0 .../{arraymodule.py => stdlib_array.py} | 0 ...t_collections.py => stdlib_collections.py} | 0 tests/snippets/{test_csv.py => stdlib_csv.py} | 0 .../{test_hashlib.py => stdlib_hashlib.py} | 0 .../{test_imghdr.py => stdlib_imghdr.py} | 0 .../{bytes_io.py => stdlib_io_bytesio.py} | 0 .../{string_io.py => stdlib_io_stringio.py} | 0 .../{test_logging.py => stdlib_logging.py} | 0 .../{math_module.py => stdlib_math.py} | 0 tests/snippets/{test_re.py => stdlib_re.py} | 0 .../{test_string.py => stdlib_string.py} | 0 .../{test_struct.py => stdlib_struct.py} | 0 tests/snippets/{sysmod.py => stdlib_sys.py} | 0 .../snippets/{test_time.py => stdlib_time.py} | 0 .../{test_xdrlib.py => stdlib_xdrlib.py} | 1 - tests/snippets/subtraction.py | 21 ----------------- tests/snippets/test_bitwise.py | 21 ----------------- tests/snippets/test_sets.py | 20 ---------------- 24 files changed, 61 insertions(+), 64 deletions(-) rename tests/snippets/{test_async_stuff.py => async_stuff.py} (100%) rename tests/snippets/{test_exec.py => builtin_exec.py} (100%) rename tests/snippets/{test_abc.py => stdlib_abc.py} (100%) rename tests/snippets/{arraymodule.py => stdlib_array.py} (100%) rename tests/snippets/{test_collections.py => stdlib_collections.py} (100%) rename tests/snippets/{test_csv.py => stdlib_csv.py} (100%) rename tests/snippets/{test_hashlib.py => stdlib_hashlib.py} (100%) rename tests/snippets/{test_imghdr.py => stdlib_imghdr.py} (100%) rename tests/snippets/{bytes_io.py => stdlib_io_bytesio.py} (100%) rename tests/snippets/{string_io.py => stdlib_io_stringio.py} (100%) rename tests/snippets/{test_logging.py => stdlib_logging.py} (100%) rename tests/snippets/{math_module.py => stdlib_math.py} (100%) rename tests/snippets/{test_re.py => stdlib_re.py} (100%) rename tests/snippets/{test_string.py => stdlib_string.py} (100%) rename tests/snippets/{test_struct.py => stdlib_struct.py} (100%) rename tests/snippets/{sysmod.py => stdlib_sys.py} (100%) rename tests/snippets/{test_time.py => stdlib_time.py} (100%) rename tests/snippets/{test_xdrlib.py => stdlib_xdrlib.py} (99%) delete mode 100644 tests/snippets/subtraction.py delete mode 100644 tests/snippets/test_bitwise.py delete mode 100644 tests/snippets/test_sets.py diff --git a/tests/snippets/test_async_stuff.py b/tests/snippets/async_stuff.py similarity index 100% rename from tests/snippets/test_async_stuff.py rename to tests/snippets/async_stuff.py diff --git a/tests/snippets/builtin_complex.py b/tests/snippets/builtin_complex.py index ba36c2885..ae83aec26 100644 --- a/tests/snippets/builtin_complex.py +++ b/tests/snippets/builtin_complex.py @@ -129,4 +129,25 @@ assert '(1-1j)' == repr(1-1j) # __getnewargs__ assert (3 + 5j).__getnewargs__() == (3.0, 5.0) -assert (5j).__getnewargs__() == (0.0, 5.0) \ No newline at end of file +assert (5j).__getnewargs__() == (0.0, 5.0) + + +class Complex(): + def __init__(self, real, imag): + self.real = real + self.imag = imag + + def __repr__(self): + return "Com" + str((self.real, self.imag)) + + def __sub__(self, other): + return Complex(self.real - other, self.imag) + + def __rsub__(self, other): + return Complex(other - self.real, -self.imag) + + def __eq__(self, other): + return self.real == other.real and self.imag == other.imag + +assert Complex(4, 5) - 3 == Complex(1, 5) +assert 7 - Complex(4, 5) == Complex(3, -5) diff --git a/tests/snippets/test_exec.py b/tests/snippets/builtin_exec.py similarity index 100% rename from tests/snippets/test_exec.py rename to tests/snippets/builtin_exec.py diff --git a/tests/snippets/math_basics.py b/tests/snippets/math_basics.py index ef6f587ce..31f47c9fb 100644 --- a/tests/snippets/math_basics.py +++ b/tests/snippets/math_basics.py @@ -51,3 +51,22 @@ assert_raises(TypeError, pow, 2, 4.0, 5) assert_raises(TypeError, pow, 2.0, 4, 5) assert_raises(ValueError, pow, 2, -1, 5) assert_raises(ValueError, pow, 2, 2, 0) + +# bitwise + +assert 8 >> 3 == 1 +assert 8 << 3 == 64 + +# Left shift raises type error +assert_raises(TypeError, lambda: 1 << 0.1) +assert_raises(TypeError, lambda: 1 << "abc") + +# Right shift raises type error +assert_raises(TypeError, lambda: 1 >> 0.1) +assert_raises(TypeError, lambda: 1 >> "abc") + +# Left shift raises value error on negative +assert_raises(ValueError, lambda: 1 << -1) + +# Right shift raises value error on negative +assert_raises(ValueError, lambda: 1 >> -1) diff --git a/tests/snippets/set.py b/tests/snippets/set.py index 46fe17ab3..69607221e 100644 --- a/tests/snippets/set.py +++ b/tests/snippets/set.py @@ -337,3 +337,23 @@ assert frozenset([1, 2]).__ne__(frozenset()) assert not frozenset([1, 2]).__ne__(set([2, 1])) assert not frozenset([1, 2]).__ne__(frozenset([2, 1])) assert frozenset().__ne__(1) == NotImplemented + +empty_set = set() +non_empty_set = set([1,2,3]) +set_from_literal = {1,2,3} + +assert 1 in non_empty_set +assert 4 not in non_empty_set + +assert 1 in set_from_literal +assert 4 not in set_from_literal + +# TODO: Assert that empty aruguments raises exception. +non_empty_set.add('a') +assert 'a' in non_empty_set + +# TODO: Assert that empty arguments, or item not in set raises exception. +non_empty_set.remove(1) +assert 1 not in non_empty_set + +# TODO: Assert that adding the same thing to a set once it's already there doesn't do anything. diff --git a/tests/snippets/test_abc.py b/tests/snippets/stdlib_abc.py similarity index 100% rename from tests/snippets/test_abc.py rename to tests/snippets/stdlib_abc.py diff --git a/tests/snippets/arraymodule.py b/tests/snippets/stdlib_array.py similarity index 100% rename from tests/snippets/arraymodule.py rename to tests/snippets/stdlib_array.py diff --git a/tests/snippets/test_collections.py b/tests/snippets/stdlib_collections.py similarity index 100% rename from tests/snippets/test_collections.py rename to tests/snippets/stdlib_collections.py diff --git a/tests/snippets/test_csv.py b/tests/snippets/stdlib_csv.py similarity index 100% rename from tests/snippets/test_csv.py rename to tests/snippets/stdlib_csv.py diff --git a/tests/snippets/test_hashlib.py b/tests/snippets/stdlib_hashlib.py similarity index 100% rename from tests/snippets/test_hashlib.py rename to tests/snippets/stdlib_hashlib.py diff --git a/tests/snippets/test_imghdr.py b/tests/snippets/stdlib_imghdr.py similarity index 100% rename from tests/snippets/test_imghdr.py rename to tests/snippets/stdlib_imghdr.py diff --git a/tests/snippets/bytes_io.py b/tests/snippets/stdlib_io_bytesio.py similarity index 100% rename from tests/snippets/bytes_io.py rename to tests/snippets/stdlib_io_bytesio.py diff --git a/tests/snippets/string_io.py b/tests/snippets/stdlib_io_stringio.py similarity index 100% rename from tests/snippets/string_io.py rename to tests/snippets/stdlib_io_stringio.py diff --git a/tests/snippets/test_logging.py b/tests/snippets/stdlib_logging.py similarity index 100% rename from tests/snippets/test_logging.py rename to tests/snippets/stdlib_logging.py diff --git a/tests/snippets/math_module.py b/tests/snippets/stdlib_math.py similarity index 100% rename from tests/snippets/math_module.py rename to tests/snippets/stdlib_math.py diff --git a/tests/snippets/test_re.py b/tests/snippets/stdlib_re.py similarity index 100% rename from tests/snippets/test_re.py rename to tests/snippets/stdlib_re.py diff --git a/tests/snippets/test_string.py b/tests/snippets/stdlib_string.py similarity index 100% rename from tests/snippets/test_string.py rename to tests/snippets/stdlib_string.py diff --git a/tests/snippets/test_struct.py b/tests/snippets/stdlib_struct.py similarity index 100% rename from tests/snippets/test_struct.py rename to tests/snippets/stdlib_struct.py diff --git a/tests/snippets/sysmod.py b/tests/snippets/stdlib_sys.py similarity index 100% rename from tests/snippets/sysmod.py rename to tests/snippets/stdlib_sys.py diff --git a/tests/snippets/test_time.py b/tests/snippets/stdlib_time.py similarity index 100% rename from tests/snippets/test_time.py rename to tests/snippets/stdlib_time.py diff --git a/tests/snippets/test_xdrlib.py b/tests/snippets/stdlib_xdrlib.py similarity index 99% rename from tests/snippets/test_xdrlib.py rename to tests/snippets/stdlib_xdrlib.py index 989a603c7..148e1c210 100644 --- a/tests/snippets/test_xdrlib.py +++ b/tests/snippets/stdlib_xdrlib.py @@ -1,4 +1,3 @@ - # This probably will be superceeded by the python unittests when that works. import xdrlib diff --git a/tests/snippets/subtraction.py b/tests/snippets/subtraction.py deleted file mode 100644 index 3471c1545..000000000 --- a/tests/snippets/subtraction.py +++ /dev/null @@ -1,21 +0,0 @@ -assert 5 - 3 == 2 - -class Complex(): - def __init__(self, real, imag): - self.real = real - self.imag = imag - - def __repr__(self): - return "Com" + str((self.real, self.imag)) - - def __sub__(self, other): - return Complex(self.real - other, self.imag) - - def __rsub__(self, other): - return Complex(other - self.real, -self.imag) - - def __eq__(self, other): - return self.real == other.real and self.imag == other.imag - -assert Complex(4, 5) - 3 == Complex(1, 5) -assert 7 - Complex(4, 5) == Complex(3, -5) diff --git a/tests/snippets/test_bitwise.py b/tests/snippets/test_bitwise.py deleted file mode 100644 index 32028c996..000000000 --- a/tests/snippets/test_bitwise.py +++ /dev/null @@ -1,21 +0,0 @@ -from testutils import assert_raises - -# -# Tests -# -assert 8 >> 3 == 1 -assert 8 << 3 == 64 - -# Left shift raises type error -assert_raises(TypeError, lambda: 1 << 0.1) -assert_raises(TypeError, lambda: 1 << "abc") - -# Right shift raises type error -assert_raises(TypeError, lambda: 1 >> 0.1) -assert_raises(TypeError, lambda: 1 >> "abc") - -# Left shift raises value error on negative -assert_raises(ValueError, lambda: 1 << -1) - -# Right shift raises value error on negative -assert_raises(ValueError, lambda: 1 >> -1) diff --git a/tests/snippets/test_sets.py b/tests/snippets/test_sets.py deleted file mode 100644 index a7ad7d19c..000000000 --- a/tests/snippets/test_sets.py +++ /dev/null @@ -1,20 +0,0 @@ - -empty_set = set() -non_empty_set = set([1,2,3]) -set_from_literal = {1,2,3} - -assert 1 in non_empty_set -assert 4 not in non_empty_set - -assert 1 in set_from_literal -assert 4 not in set_from_literal - -# TODO: Assert that empty aruguments raises exception. -non_empty_set.add('a') -assert 'a' in non_empty_set - -# TODO: Assert that empty arguments, or item not in set raises exception. -non_empty_set.remove(1) -assert 1 not in non_empty_set - -# TODO: Assert that adding the same thing to a set once it's already there doesn't do anything.