From 8f06108431137d4c259c019096b1fc2c5c6c48d6 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Sun, 11 Mar 2018 03:06:10 +0900 Subject: [PATCH 1/3] Proper unit tests for Python __hash__() behavior [changelog skip] --- test/python/primitive_test.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/python/primitive_test.py b/test/python/primitive_test.py index ba9a064..65e05f6 100644 --- a/test/python/primitive_test.py +++ b/test/python/primitive_test.py @@ -29,8 +29,8 @@ def test_float_unbox(): assert {float_unbox, float_unbox, float1} == {float_unbox, float1} assert float_unbox.__nirum_serialize__() == 3.14 assert FloatUnbox.__nirum_deserialize__(3.14) == float_unbox - assert hash(float_unbox) - assert hash(float_unbox) != 3.14 + assert hash(float_unbox) == hash(FloatUnbox(3.14)) + assert hash(float_unbox) != hash(float1) with raises(ValueError): FloatUnbox.__nirum_deserialize__('a') with raises(TypeError): @@ -102,7 +102,9 @@ def test_record(): assert point != Point1(left=4, top=14) assert point != Point1(left=4, top=15) assert point != 'foo' - assert hash(Point1(left=3, top=14)) + assert hash(point) == hash(Point1(left=3, top=14)) + assert hash(point) != hash(Point1(left=0, top=14)) + assert hash(point) != hash(Point1(left=3, top=0)) point_serialized = {'_type': 'point1', 'x': 3, 'top': 14} assert point.__nirum_serialize__() == point_serialized assert Point1.__nirum_deserialize__(point_serialized) == point @@ -135,6 +137,9 @@ def test_record(): assert point2 != Point2(left=IntUnbox(4), top=IntUnbox(14)) assert point2 != Point2(left=IntUnbox(4), top=IntUnbox(15)) assert point2 != 'foo' + assert hash(point2) == hash(Point2(left=IntUnbox(3), top=IntUnbox(14))) + assert hash(point2) != hash(Point2(left=IntUnbox(0), top=IntUnbox(14))) + assert hash(point2) != hash(Point2(left=IntUnbox(3), top=IntUnbox(0))) point2_serialize = {'_type': 'point2', 'left': 3, 'top': 14} assert point2.__nirum_serialize__() == point2_serialize assert Point2.__nirum_deserialize__(point2_serialize) == point2 @@ -228,7 +233,16 @@ def test_union(): middle_name=u'wrong', last_name=u'wrong') assert hash(WesternName(first_name=u'foo', middle_name=u'bar', - last_name=u'baz')) + last_name=u'baz')) == hash(western_name) + assert hash(western_name) != hash( + WesternName(first_name=u'', middle_name=u'bar', last_name=u'baz') + ) + assert hash(western_name) != hash( + WesternName(first_name=u'foo', middle_name=u'', last_name=u'baz') + ) + assert hash(western_name) != hash( + WesternName(first_name=u'foo', middle_name=u'bar', last_name=u'') + ) if PY3: assert repr(western_name) == ( "fixture.foo.MixedName.WesternName(first_name='foo', " From 225b1827a08df11c9abb52123c24acb40a37322e Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Sun, 11 Mar 2018 04:22:28 +0900 Subject: [PATCH 2/3] Incompatibilities between BSD sed and GNU sed Whereas GNU sed's -i/--in-place option optionally takes an argument (which is a suffix, and means to modify the input file in place if you omit an argument), BSD sed's -i option always takes an argument even if it's an empty string (e.g., -i ''). My solution is install GNU sed using Homebrew on macOS build. Note that omitting --with-default-names will prepend "g" to the command, i.e., gsed. [changelog skip] --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c05f19b..c29c872 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,6 +78,7 @@ before_install: brew update || true brew upgrade || true brew update || true + brew install --with-default-names gnu-sed brew tap dahlia/homebrew-deadsnakes brew install python34 python35 python3 || \ brew upgrade python34 python35 python3 || \ From 208b2229c1c139d61e0a5767a49af10a9263bd28 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Sun, 11 Mar 2018 06:09:38 +0900 Subject: [PATCH 3/3] Fix broken tox finding on macOS build Cherry-picked from d80195a3f3ef7b2e170af594cd78ecffa7c8bd56 [changelog skip] --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c29c872..eac679e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -119,7 +119,8 @@ install: fi script: -- 'TOX="$(which tox)" stack --no-terminal test -j4 --coverage' +- ls -al "$(python3 -m site --user-base)/bin/tox" +- 'TOX="$(python3 -m site --user-base)/bin/tox" stack --no-terminal test -j4 --coverage' - ./lint.sh after_script: