Skip to content

[MRG] Replace assert_* methods with "assert" keyword statements.#430

Merged
lesteve merged 5 commits intojoblib:masterfrom
kdexd:pythonic-asserts
Nov 30, 2016
Merged

[MRG] Replace assert_* methods with "assert" keyword statements.#430
lesteve merged 5 commits intojoblib:masterfrom
kdexd:pythonic-asserts

Conversation

@kdexd
Copy link
Copy Markdown

@kdexd kdexd commented Nov 26, 2016

Second Phase PR on #411 ( Succeeding PR #422 )

Native Python ships exceptions module which has an implementation of AssertionError. This exception is raised when any statement using assert keyword is incorrect. When the tests are run with py.test, this is overriden by _pytest.assertion.reinterpret.AssertionError.
Hence instead of using assert_true, assert_false, assert_equal and assert_not_equal methods, using assert keyword statements provides a helpful error log for debugging upon failing tests using py.test command.

Besides this, the replacement can be welcoming because:

assert_true(a == b)
assert_equal(a, b)
assert_false(a != b)

# ... all these have same meaning hence can disturb uniformity, whereas
assert a == b 
# looks clearer and more pythonic

Execution with py.test causes three tests to fail, which will be taken up just after this PR.

@kdexd kdexd changed the title Replace assert_* methods with "assert" keyword statements. [MRG] Replace assert_* methods with "assert" keyword statements. Nov 26, 2016
@kdexd
Copy link
Copy Markdown
Author

kdexd commented Nov 26, 2016

@lesteve Expect another PR once this is done. I'm here for addressing your reviews, if any 😄
CC: @aabadie @GaelVaroquaux

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 28, 2016

LGTM in general. There is an assert_less than you missed:

$ git grep 'assert_less'
joblib/test/test_hashing.py:def assert_less(a, b):
joblib/test/test_hashing.py:    assert_less(relative_diff, 0.3)
joblib/test/test_hashing.py:    assert_less(relative_diff, 0.3)

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 28, 2016

And some assert_equal or assert_not_equal that can still be removed I think

$ git grep -P 'assert_equal|assert_not_equal' | grep -v yield
joblib/test/test_disk.py:from joblib.testing import assert_equal, assert_raises
joblib/test/test_func_inspect.py:from joblib.testing import (assert_equal, assert_raises_regex, assert_raises)
joblib/test/test_hashing.py:from joblib.testing import (assert_equal, assert_not_equal,
joblib/test/test_memory.py:from joblib.testing import (assert_equal, assert_true, assert_false,
joblib/test/test_numpy_pickle.py:from joblib.testing import (assert_equal, assert_raises, assert_raises_regex,
joblib/test/test_numpy_pickle.py:                np.testing.assert_equal(result, expected)
joblib/test/test_numpy_pickle.py:                    np.testing.assert_equal(result, expected)
joblib/test/test_parallel.py:from joblib.testing import (assert_equal, assert_raises, check_subprocess_call,
joblib/test/test_parallel.py:    assert_equal(queue, [
joblib/test/test_parallel.py:    assert_equal(queue, [
joblib/test/test_parallel.py:    assert_equal(first_four,
joblib/testing.py:assert_equal = _dummy.assertEqual
joblib/testing.py:assert_not_equal = _dummy.assertNotEqual

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 28, 2016

I originally thought that bare assert would not play nice with nosetests (not sure why maybe it was the case at one point) but actually I tried and nosetests seem to support as well as the assert_ helpers maybe the error message is not as nice but I don't think we care that much as long as it does not take us too much time to transition to py.test.

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 28, 2016

All the assert_true and assert_false can go as well eventually.

@kdexd
Copy link
Copy Markdown
Author

kdexd commented Nov 29, 2016

I missed regex replacement of assert_less - thanks for pointing out. Also thanks for this terminal log. I am familiar with grep but this wonderful checking hack didn't strike me! I'll be using it henceforth 😄

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 29, 2016

You still have a few assert_* imports that you can remove without any harm i.e. things
from joblib.testing import assert_equal. Look at the git grep I posted above.

@kdexd
Copy link
Copy Markdown
Author

kdexd commented Nov 29, 2016

@lesteve I have left the assert_* used with yield statements untouched as I can yield an assert keyword and nose could execute it. That has to be done in phase 3 where parametrization of tests replaces yield based tests. Also, we cannot get rid of np.testing.assert_* at the moment as they deal with comparison of ndarrays specifically. e point me to some place if it is still missing from the ones I mentioned.

@kdexd
Copy link
Copy Markdown
Author

kdexd commented Nov 29, 2016

Meanwhile I would like to give an update - I have tested on both Travis and Appveyor - my fork has commits which have py.test command in Makefile, and both CIs are green 💚 😄

Once that comes in position, I will ⭐ pytestify ⭐ each module (already done two modules on my local git repo! I fear getting entangled so I am introducing small incremental changes on Github 😅

If we keep up the pace, this migration would be done before the year ends ! 🏁

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 30, 2016

@lesteve I have left the assert_* used with yield statements untouched as I can yield an assert keyword and nose could execute it.

Good point sorry I missed that.

I fear getting entangled so I am introducing small incremental changes on Github 😅

This is definitely the best way to get PR reviewed and merged quickly, thanks a lot for that!

If we keep up the pace, this migration would be done before the year ends ! 🏁

Sounds great!

around import statements that fit on one line.
@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 30, 2016

I have pushed a small cosmetic change in your branch. I will merge once the CIs are green.

@lesteve lesteve merged commit 56784b9 into joblib:master Nov 30, 2016
@lesteve
Copy link
Copy Markdown
Member

lesteve commented Nov 30, 2016

Merging, thanks a lot @karandesai-96!

@kdexd kdexd deleted the pythonic-asserts branch November 30, 2016 11:05
yarikoptic added a commit to yarikoptic/joblib that referenced this pull request Dec 8, 2016
* commit '0.10.2-55-g660fe5d': (52 commits)
  MAINT simplify way to skip doctests
  Do not print frames with IPython internals in format_stack
  BF(TST): compare for version in pickled filename ignoring full path, and looking for _ as well (joblib#445)
  [MRG] Remove nose dependency completely. (joblib#441)
  MAINT add Python 3.5 in setup.py
  Remove some Python 2.6 specific code
  [MRG] Make test execution on CI possible through py.test command. (joblib#433)
  Remove more python 2.6 related code (joblib#440)
  [MRG] Use commit range for diff in flake8_diff.sh (joblib#439)
  MAINT remove support for python 2.6 (joblib#437)
  Improve doc about caching methods (joblib#432)
  Get the tests passing with py.test
  MAINT update flake8_diff.sh
  COSMIT move stdlib imports where they belong
  [MRG] Replace assert_* methods with "assert" keyword statements. (joblib#430)
  Reraise when the exception is not a TransportableException (joblib#429)
  Make sure LICENSE.txt is included in the wheel
  Add LICENSE.txt
  Update doc/paralle.rst
  [MRG+1] Remove all nose imports from test scripts. (joblib#422)
  ...
yarikoptic added a commit to yarikoptic/joblib that referenced this pull request Dec 8, 2016
* releases: (52 commits)
  MAINT simplify way to skip doctests
  Do not print frames with IPython internals in format_stack
  BF(TST): compare for version in pickled filename ignoring full path, and looking for _ as well (joblib#445)
  [MRG] Remove nose dependency completely. (joblib#441)
  MAINT add Python 3.5 in setup.py
  Remove some Python 2.6 specific code
  [MRG] Make test execution on CI possible through py.test command. (joblib#433)
  Remove more python 2.6 related code (joblib#440)
  [MRG] Use commit range for diff in flake8_diff.sh (joblib#439)
  MAINT remove support for python 2.6 (joblib#437)
  Improve doc about caching methods (joblib#432)
  Get the tests passing with py.test
  MAINT update flake8_diff.sh
  COSMIT move stdlib imports where they belong
  [MRG] Replace assert_* methods with "assert" keyword statements. (joblib#430)
  Reraise when the exception is not a TransportableException (joblib#429)
  Make sure LICENSE.txt is included in the wheel
  Add LICENSE.txt
  Update doc/paralle.rst
  [MRG+1] Remove all nose imports from test scripts. (joblib#422)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants