-
Notifications
You must be signed in to change notification settings - Fork 95
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 #46 from cwacek/fix/8-string-representations
Fix #8. Python 3 removes support for __cmp__.
- Loading branch information
Showing
3 changed files
with
62 additions
and
10 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,51 @@ | ||
import pytest | ||
|
||
import python_jsonschema_objects as pjo | ||
|
||
|
||
@pytest.fixture | ||
def test_instance(): | ||
schema = { | ||
'title': 'Example', | ||
'properties': { | ||
'stringProp': {'type': 'string'}, | ||
'arrayProp': { | ||
'type': 'array', | ||
'items': { | ||
'type': 'string', | ||
} | ||
} | ||
} | ||
} | ||
|
||
builder = pjo.ObjectBuilder(schema) | ||
ns = builder.build_classes() | ||
instance = ns.Example( | ||
stringProp='This seems fine', | ||
arrayProp=['these', 'are', 'problematic'] | ||
) | ||
return instance | ||
|
||
|
||
def test_string_properties_compare_to_strings(test_instance): | ||
test = test_instance.stringProp == "This seems fine" | ||
assert test | ||
|
||
|
||
def test_arrays_of_strings_compare_to_strings(test_instance): | ||
test = test_instance.arrayProp == ['these', 'are', 'problematic'] | ||
assert test | ||
|
||
|
||
def test_array_elements_compare_to_types(test_instance): | ||
elem = test_instance.arrayProp[0] | ||
test = elem == 'these' | ||
assert test | ||
|
||
def test_repr_shows_property_values(test_instance): | ||
expected = "<example/arrayProp_<anonymous_field> these>" | ||
assert repr(test_instance.arrayProp[0]) == expected | ||
|
||
def test_str_shows_just_strings(test_instance): | ||
test = str(test_instance.arrayProp[0]) | ||
assert test == 'these' |
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,6 +1,6 @@ | ||
|
||
[tox] | ||
envlist = py27, py34 | ||
envlist = py27, py35 | ||
|
||
[testenv] | ||
;install_command = pip install {opts} {packages} | ||
|