Skip to content

Commit

Permalink
Merge d78964c into d649c09
Browse files Browse the repository at this point in the history
  • Loading branch information
Micah Hausler committed May 4, 2015
2 parents d649c09 + d78964c commit 9c39031
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[run]
omit =
*/version.py
[report]
exclude_lines =
# Have to re-enable the standard pragma
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ htmlcov/
# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info
/*.egg
.eggs/*

# Virtualenv
env/
Expand Down
4 changes: 4 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Release Notes
=============

v0.4.0
------
* Fixed ``__eq__`` and ``__ne__`` where 'other' doesn't have attribute.

v0.3
----
* ``compare_on_attr`` decorator no longer checks that class has attribute
Expand Down
4 changes: 4 additions & 0 deletions python3_utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def gt(this, other):
cls.__gt__ = gt

def eq(this, other):
if not hasattr(other, self.attr):
return False
return getattr(this, self.attr) == getattr(other, self.attr)
cls.__eq__ = eq

Expand All @@ -67,6 +69,8 @@ def ge(this, other):
cls.__ge__ = ge

def ne(this, other):
if not hasattr(other, self.attr):
return True
return getattr(this, self.attr) != getattr(other, self.attr)
cls.__ne__ = ne
return cls
14 changes: 12 additions & 2 deletions python3_utils/tests/decorator_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MockObject(object):
id = None

def __init__(self, id=None):
self.id = id or uuid.uuid4()
self.id = id or uuid.uuid4() # pragma: no cover


@compare_on_attr()
Expand Down Expand Up @@ -53,6 +53,11 @@ def test_eq(self):
self.model1 == MockModel(1)
)

def test_eq_no_attr(self):
self.assertFalse(
MockModelCount(2) == MockModel(2)
)

def test_le(self):
self.assertTrue(
self.model1 <= MockModel(1)
Expand All @@ -75,6 +80,11 @@ def test_ne(self):
self.model2 != self.model1
)

def test_ne_no_attr(self):
self.assertTrue(
MockModelCount(1) != self.model1
)

def test_different_attr(self):
self.assertTrue(
MockModelCount(2) >= MockModelCount(1)
Expand All @@ -83,7 +93,7 @@ def test_different_attr(self):
def test_not_decorating_class(self):
@compare_on_attr(attr='count')
def myFunc(one):
return one
return one # pragma: no cover

self.assertFalse(
hasattr(myFunc, 'count')
Expand Down
2 changes: 1 addition & 1 deletion python3_utils/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3'
__version__ = '0.4.0'
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ def get_version():
'nose>=1.3.0',
]

install_requires = [
'six>=1.8.0'
]

extras_require = {
'test': tests_require,
'packaging': ['wheel'],
'docs': ['Sphinx>=1.2.2', 'sphinx_rtd_theme'],
}

everything = set()
everything = set(install_requires)
for deps in extras_require.values():
everything.update(deps)
extras_require['all'] = list(everything)
Expand All @@ -53,9 +57,7 @@ def get_version():
'Operating System :: OS Independent',
],
license='MIT',
install_requires=[
'six>=1.8.0'
],
install_requires=install_requires,
include_package_data=True,
test_suite='nose.collector',
tests_require=tests_require,
Expand Down

0 comments on commit 9c39031

Please sign in to comment.