-
Notifications
You must be signed in to change notification settings - Fork 1
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 #49 from pepkit/dev
version 0.12
- Loading branch information
Showing
12 changed files
with
93 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,4 @@ Thumbs.db | |
build/ | ||
dist/ | ||
attmap.egg-info/ | ||
|
||
docs/autodoc_build |
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 |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
__author__ = "Vince Reuter" | ||
__email__ = "[email protected]" | ||
|
||
__all__ = ["AttMapLike"] | ||
|
||
|
||
_LOGGER = get_logger(__name__) | ||
|
||
|
@@ -134,13 +136,14 @@ def to_dict(self): | |
""" | ||
return self._simplify_keyvalue(self.items(), dict) | ||
|
||
def to_yaml(self): | ||
def to_yaml(self, trailing_newline=True): | ||
""" | ||
Get text for YAML representation. | ||
:param bool trailing_newline: whether to add trailing newline | ||
:return str: YAML text representation of this instance. | ||
""" | ||
return "\n".join(self.get_yaml_lines()) | ||
return "\n".join(self.get_yaml_lines()) + ("\n" if trailing_newline else "") | ||
|
||
def _data_for_repr(self): | ||
""" | ||
|
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 +1 @@ | ||
__version__ = "0.11" | ||
__version__ = "0.12" |
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
# Use cases and "how-to..." | ||
|
||
## ...customize a subtype's text rendition | ||
In a subclass, override `_excl_from_repr`, using key and/or type of value. | ||
|
||
The most basic implementation is a no-op, excluding nothing: | ||
```python | ||
def _excl_from_repr(self, k, cls): | ||
return False | ||
``` | ||
|
||
To exclude by key, though, you can do something like: | ||
```python | ||
def _excl_from_repr(self, k, cls): | ||
protected = ["reserved_metadata", "REZKEY"] | ||
return k in protected | ||
``` | ||
|
||
To exclude by value type, you can use something like: | ||
```python | ||
def _excl_from_repr(self, k, cls): | ||
return issubclass(cls, BaseOmissionType) | ||
``` | ||
where `BaseOmissionType` is a proxy for the name of some type of values that may | ||
be stored in your mapping but that you prefer to not display in its text representation. | ||
|
||
The two kinds of exclusion criteria may be combined as desired. |
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 +1 @@ | ||
ubiquerg>=0.0.5 | ||
ubiquerg>=0.2.1 |
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,19 +1,38 @@ | ||
""" Validate what's available directly on the top-level import. """ | ||
|
||
from abc import ABCMeta | ||
from collections import OrderedDict | ||
from inspect import isclass, isfunction | ||
import itertools | ||
import pytest | ||
import attmap | ||
from attmap import * | ||
|
||
__author__ = "Vince Reuter" | ||
__email__ = "[email protected]" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["obj_name", "typecheck"], | ||
[("AttMap", isclass), ("OrdAttMap", isclass), ("PathExAttMap", isclass), | ||
("AttMapEcho", isclass), ("get_data_lines", isfunction)]) | ||
def get_base_check(*bases): | ||
""" | ||
Build function to validate an type's base classes. | ||
:param bases: sequence of base types. | ||
:return function(type) -> bool: function that checks a type's base classes | ||
for equivalence with the sequence given here. | ||
""" | ||
return lambda obj: obj.__bases__ == bases | ||
|
||
|
||
@pytest.mark.parametrize(["obj_name", "typecheck"], itertools.chain(*[ | ||
[("AttMapLike", f) for f in [isclass, lambda obj: obj.__metaclass__ == ABCMeta]], | ||
[("AttMap", f) for f in [isclass, get_base_check(AttMapLike)]], | ||
[("OrdAttMap", f) for f in [isclass, get_base_check(OrderedDict, AttMap)]], | ||
[("PathExAttMap", f) for f in [isclass, get_base_check(OrdAttMap)]], | ||
[("AttMapEcho", f) for f in [isclass, get_base_check(PathExAttMap)]], | ||
[("get_data_lines", isfunction)] | ||
])) | ||
def test_top_level_exports(obj_name, typecheck): | ||
""" At package level, validate object availability and type. """ | ||
import attmap | ||
mod = attmap | ||
try: | ||
obj = getattr(mod, obj_name) | ||
|
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