Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from neilvyas/neilvyas/fix-pvector-field-type…
…-enum-arg Fix how fields handle type arguments.
- Loading branch information
Showing
4 changed files
with
122 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from six import string_types | ||
|
||
|
||
# enum compat | ||
try: | ||
from enum import Enum | ||
except: | ||
class Enum(object): pass | ||
# no objects will be instances of this class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
from pyrsistent import field | ||
from pyrsistent._compat import Enum | ||
|
||
from pyrsistent import field, pvector_field | ||
|
||
def test_enum(): | ||
try: | ||
from enum import Enum | ||
except ImportError: | ||
# skip enum test if Enums are not available | ||
return | ||
|
||
class TestEnum(Enum): | ||
x = 1 | ||
y = 2 | ||
# NB: This derives from the internal `pyrsistent._compat.Enum` in order to | ||
# simplify coverage across python versions. Since we use | ||
# `pyrsistent._compat.Enum` in `pyrsistent`'s implementation, it's useful to | ||
# use it in the test coverage as well, for consistency. | ||
class TestEnum(Enum): | ||
x = 1 | ||
y = 2 | ||
|
||
|
||
def test_enum(): | ||
f = field(type=TestEnum) | ||
|
||
assert TestEnum in f.type | ||
assert len(f.type) == 1 | ||
|
||
|
||
# This is meant to exercise `_seq_field`. | ||
def test_pvector_field_enum_type(): | ||
f = pvector_field(TestEnum) | ||
|
||
assert len(f.type) == 1 | ||
assert TestEnum is list(f.type)[0].__type__ |