Skip to content

Commit

Permalink
fix __INGORE_INVALID_NAME__ issue
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelchen committed May 29, 2019
1 parent a592fc9 commit 07ec809
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 1.1.1

Fix issue that `__IGNORE_INVALID_NAME__` does not work.

# 1.1.0

Change `Option` to make its instance object same as its `code`.
Expand Down
4 changes: 2 additions & 2 deletions optenum/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __new__(cls, name, bases, namespace):
name_options_mapping = {}
code_options_mapping = {}

ignore_invalid_name = getattr(cls, '__IGNORE_INVALID_NAME__', False)
order_by = getattr(cls, '__ORDER_BY__', None)
ignore_invalid_name = namespace.get('__IGNORE_INVALID_NAME__', False)
order_by = namespace.get('__ORDER_BY__', None)

if not isinstance(ignore_invalid_name, bool):
raise ValueError("'__IGNORE_INVALID_NAME__' must be bool type True or False.")
Expand Down
2 changes: 1 addition & 1 deletion optenum/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" version file """

__version__ = '1.1.0'
__version__ = '1.1.1'
1 change: 1 addition & 0 deletions tests/test_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Favorite(object):
APPLE = Option(1, 'APPLE', 'Apple')
BANANA = Option(2, 'BANANA', 'Banana')


store = {
1: '10 Apples', # Apple = 1
2: '20 Bananas', # Banana = 2
Expand Down
16 changes: 16 additions & 0 deletions tests/test_options_customized.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ def test_get_dict(self):
self.assertEqual(len(apple), 2)
self.assertIn(Fruit.APPLE, apple)

def test_ignore_invalid_name(self):

# invalid name
try:
class Bar(Options):
Invalid= (1, 2)
except Exception as e:
self.assertIsInstance(e, AttributeError)

# ignore invalid name
class Foo(Options):
__IGNORE_INVALID_NAME__ = True
Ignored = (1, 2)

self.assertEqual(Foo.Ignored, (1, 2))


if __name__ == '__main__':
unittest.main()

0 comments on commit 07ec809

Please sign in to comment.