Skip to content

Commit

Permalink
Version 3.4.4 (cdgriffith#103)
Browse files Browse the repository at this point in the history
* Fixing issue with pop not resetting heritage properly (Thanks to Jeremiah Lowin)
  • Loading branch information
cdgriffith authored Sep 23, 2019
1 parent cd9ba15 commit 1a63d7b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Suggestions and bug reporting:
- (deluxghost)
- Nikolay Stanishev (nikolaystanishev)
- Craig Quiter (crizCraig)
- Jeremiah Lowin (jlowin)
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
---------

Version 3.4.4
~~~~~~~~~~~~~

* Fixing pop not properly resetting box_heritage (thanks to Jeremiah Lowin)

Version 3.4.3
~~~~~~~~~~~~~

Expand Down
6 changes: 5 additions & 1 deletion box.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
__all__ = ['Box', 'ConfigBox', 'BoxList', 'SBox',
'BoxError', 'BoxKeyError']
__author__ = 'Chris Griffith'
__version__ = '3.4.3'
__version__ = '3.4.4'

BOX_PARAMETERS = ('default_box', 'default_box_attr', 'conversion_box',
'frozen_box', 'camel_killer_box', 'box_it_up',
Expand Down Expand Up @@ -592,13 +592,17 @@ def pop(self, key, *args):
return args[0]
else:
del self[key]
if isinstance(item, Box):
item._box_config['__box_heritage'] = ()
return item
try:
item = self[key]
except KeyError:
raise BoxKeyError('{0}'.format(key))
else:
del self[key]
if isinstance(item, Box):
item._box_config['__box_heritage'] = ()
return item

def clear(self):
Expand Down
12 changes: 12 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@
PY3 = sys.version_info >= (3, 0)

test_root = os.path.abspath(os.path.dirname(__file__))
data_dir = os.path.join(test_root, "data")
tmp_dir = os.path.join(test_root, "tmp")

try:
os.makedirs(data_dir)
except OSError:
pass

try:
os.makedirs(tmp_dir)
except OSError:
pass


test_dict = {'key1': 'value1',
'not$allowed': 'fine_value',
'BigCamel': 'hi',
Expand Down
17 changes: 11 additions & 6 deletions test/test_functional_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestBoxFunctional(unittest.TestCase):
def temp_dir_cleanup(self):
shutil.rmtree(tmp_dir, ignore_errors=True)
try:
os.mkdir(tmp_dir)
os.makedirs(tmp_dir)
except OSError:
pass
yield
Expand Down Expand Up @@ -625,15 +625,19 @@ def test_pickle(self):
pic_file = os.path.join(tmp_dir, 'test.p')
pic2_file = os.path.join(tmp_dir, 'test.p2')
bb = Box(movie_data, conversion_box=False)
pickle.dump(bb, open(pic_file, 'wb'))
loaded = pickle.load(open(pic_file, 'rb'))
with open(pic_file, 'wb') as pf:
pickle.dump(bb, pf)
with open(pic_file, 'rb') as pf:
loaded = pickle.load(pf)
assert bb == loaded
assert loaded._box_config['conversion_box'] is False

ll = [[Box({'a': 'b'}, ordered_box=True)], [[{'c': 'g'}]]]
bx = BoxList(ll)
pickle.dump(bx, open(pic2_file, 'wb'))
loaded2 = pickle.load(open(pic2_file, 'rb'))
with open(pic2_file, 'wb') as pf:
pickle.dump(bx, pf)
with open(pic2_file, 'rb') as pf:
loaded2 = pickle.load(pf)
assert bx == loaded2
loaded2.box_options = bx.box_options

Expand Down Expand Up @@ -747,8 +751,9 @@ class MyList(list):
assert isinstance(bl[0], BoxList)

def test_pop(self):
bx = Box(a=4, c={"d": 3})
bx = Box(a=4, c={"d": 3}, b={"h": {"y": 2}})
assert bx.pop('a') == 4
assert bx.pop('b').h.y == 2
with pytest.raises(BoxKeyError):
bx.pop('b')
assert bx.pop('a', None) is None
Expand Down

0 comments on commit 1a63d7b

Please sign in to comment.