Skip to content

Commit

Permalink
Merge pull request #35 from vreuter/dev
Browse files Browse the repository at this point in the history
0.9
  • Loading branch information
vreuter authored May 15, 2019
2 parents 069576a + bc1de54 commit 0cae76c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions attmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from .attmap_echo import AttMapEcho
from .helpers import *
from .ordattmap import OrdAttMap
from .ordpathex_attmap import OrdPathExAttMap
from .pathex_attmap import PathExAttMap
from ._version import __version__

AttributeDict = AttMap
AttributeDictEcho = AttMapEcho

__all__ = ["AttMap", "AttMapEcho", "AttributeDict", "AttributeDictEcho",
"OrdAttMap", "OrdPathExAttMap", "get_data_lines"]
"OrdAttMap", "PathExAttMap", "get_data_lines"]
2 changes: 1 addition & 1 deletion attmap/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8"
__version__ = "0.9"
4 changes: 2 additions & 2 deletions attmap/attmap_echo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""" AttMap that echoes an unset key/attr """

from .ordpathex_attmap import OrdPathExAttMap
from .pathex_attmap import PathExAttMap


class AttMapEcho(OrdPathExAttMap):
class AttMapEcho(PathExAttMap):
""" An AttMap that returns key/attr if it has no set value. """

def __getattr__(self, item, default=None):
Expand Down
6 changes: 3 additions & 3 deletions attmap/ordpathex_attmap.py → attmap/pathex_attmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
__email__ = "[email protected]"


__all__ = ["OrdPathExAttMap"]
__all__ = ["PathExAttMap"]


class OrdPathExAttMap(OrdAttMap):
class PathExAttMap(OrdAttMap):
""" Used in pepkit projects, with Mapping conversion and path expansion """

@property
def _transformations(self):
""" Add path expansion behavior to more general attmap. """
return super(OrdPathExAttMap, self)._transformations + \
return super(PathExAttMap, self)._transformations + \
[(lambda obj: isinstance(obj, str), expandpath)]
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.9] - 2019-05-14
### Changed
- `OrdPathAttExAttMap` is now `PathExAttMap`.

## [0.8] - 2019-05-13
### Added
- `OrdAttMap` to create maps that preserve insertion order and otherwise behave like ordinary `AttMap`
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


ALL_ATTMAPS = [AttributeDict, AttributeDictEcho, AttMap, OrdAttMap, AttMapEcho,
OrdPathExAttMap]
PathExAttMap]


@pytest.fixture(scope="function", params=ALL_ATTMAPS)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_attmap_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from pandas import DataFrame as DF, Series
import pytest
from attmap import AttMap, OrdAttMap, OrdPathExAttMap, AttMapEcho
from attmap import AttMap, OrdAttMap, PathExAttMap, AttMapEcho
from .conftest import ALL_ATTMAPS
from .helpers import get_att_map

Expand Down Expand Up @@ -56,10 +56,10 @@ def test_eq_with_scistack_value_types(attmap_type, obj1, obj2, expected):
@pytest.mark.parametrize("data", [{}, {"a": 1}])
@pytest.mark.parametrize(["this_type", "that_type", "exp"], [
(AttMap, AttMap, True),
(AttMap, AttMapEcho, False), (AttMap, OrdAttMap, False), (AttMap, OrdPathExAttMap, False),
(AttMap, AttMapEcho, False), (AttMap, OrdAttMap, False), (AttMap, PathExAttMap, False),
(OrdAttMap, OrdAttMap, True),
(OrdAttMap, OrdPathExAttMap, False), (OrdAttMap, AttMapEcho, False),
(OrdPathExAttMap, OrdPathExAttMap, True), (OrdPathExAttMap, AttMapEcho, False),
(OrdAttMap, PathExAttMap, False), (OrdAttMap, AttMapEcho, False),
(PathExAttMap, PathExAttMap, True), (PathExAttMap, AttMapEcho, False),
(AttMapEcho, AttMapEcho, True)])
def test_equality_is_strict_in_type(data, this_type, that_type, exp):
""" Attmap equality requires exact type match. """
Expand Down
12 changes: 6 additions & 6 deletions tests/test_ordattmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from hypothesis import given
from hypothesis.strategies import *
from attmap import AttMap, AttMapEcho, OrdAttMap, OrdPathExAttMap
from attmap import AttMap, AttMapEcho, OrdAttMap, PathExAttMap

__author__ = "Vince Reuter"
__email__ = "[email protected]"
Expand Down Expand Up @@ -38,15 +38,15 @@ def kv_lists_strategy(pool=(integers, text, characters, uuids), **kwargs):

@pytest.mark.parametrize(["cls", "exp"], [
(OrdAttMap, True), (OrderedDict, True), (AttMap, True),
(OrdPathExAttMap, False), (AttMapEcho, False)])
(PathExAttMap, False), (AttMapEcho, False)])
def test_subclassing(cls, exp):
""" Verify that OrdAttMap type has expected type memberships. """
assert exp is issubclass(OrdAttMap, cls)


@pytest.mark.parametrize(["cls", "exp"], [
(OrdAttMap, True), (OrderedDict, True), (AttMap, True),
(OrdPathExAttMap, False), (AttMapEcho, False)])
(PathExAttMap, False), (AttMapEcho, False)])
def test_type_membership(cls, exp):
""" Verify that an OrdAttMap instance passes type checks as expected. """
assert exp is isinstance(OrdAttMap(), cls)
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_ordattmap_deletion(hwy_dat_key, raw_hwy_dat, alter, check):
assert check(orig, obs), "Expected {} but found {}".format(orig, obs)


@pytest.mark.parametrize("base_type", [OrdAttMap, OrdPathExAttMap])
@pytest.mark.parametrize("base_type", [OrdAttMap, PathExAttMap])
@pytest.mark.parametrize(
["that_type", "final_exp"],
[(dict, sys.version_info >= (3, 6)), (OrderedDict, True), (OrdAttMap, True)])
Expand Down Expand Up @@ -166,7 +166,7 @@ def _excl_from_repr(self, k, cls):

@pytest.mark.parametrize(["that_type", "exp"], [
(OrdAttMap, True), (AttMapEcho, False), (AttMap, False),
(OrdPathExAttMap, False), (OrderedDict, False), (dict, False)])
(PathExAttMap, False), (OrderedDict, False), (dict, False)])
def test_ordattmap_repr(raw_hwy_dat, that_type, exp):
""" Test __repr__ of OrdAttMap. """
assert exp is (repr(OrdAttMap(raw_hwy_dat)) == repr(that_type(raw_hwy_dat)))
Expand All @@ -178,7 +178,7 @@ class BasicDataTests:
BASIC_DATA = [("a", OrderedDict([("c", 3), ("b", 2)])), ("d", 4),
("e", OrderedDict([("f", 6)]))]

@pytest.fixture(params=[OrdAttMap, OrdPathExAttMap])
@pytest.fixture(params=[OrdAttMap, PathExAttMap])
def oam(self, request):
""" Provide test case with a simple ordered attmap instance. """
return request.param(self.BASIC_DATA)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.mark.parametrize(
["obj_name", "typecheck"],
[("AttMap", isclass), ("OrdAttMap", isclass), ("OrdPathExAttMap", isclass),
[("AttMap", isclass), ("OrdAttMap", isclass), ("PathExAttMap", isclass),
("AttMapEcho", isclass), ("get_data_lines", isfunction)])
def test_top_level_exports(obj_name, typecheck):
""" At package level, validate object availability and type. """
Expand Down
2 changes: 1 addition & 1 deletion tests/test_path_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@pytest.fixture(scope="function")
def pam():
""" Provide a test case with a clean/fresh map. """
return OrdPathExAttMap()
return PathExAttMap()


class TmpEnv(object):
Expand Down

0 comments on commit 0cae76c

Please sign in to comment.