def test_bunch_methods(): b = nib.Bunch(a=2) b.update(a=3) newb = b.dictcopy() assert b.a == 3 assert b.get('a') == 3 assert b.get('badkey', 'otherthing') == 'otherthing' assert b != newb assert type(dict()) == type(newb) assert newb['a'] == 3
def test_bunch_methods(): b = nib.Bunch(a=2) b.update(a=3) newb = b.dictcopy() yield assert_equal, b.a, 3 yield assert_equal, b.get('a'), 3 yield assert_equal, b.get('badkey', 'otherthing'), 'otherthing' yield assert_not_equal, b, newb yield assert_equal, type(dict()), type(newb) yield assert_equal, newb['a'], 3
def test_bunch_hash(): # NOTE: Since the path to the json file is included in the Bunch, # the hash will be unique to each machine. pth = os.path.split(os.path.abspath(__file__))[0] json_pth = os.path.join(pth, 'realign_json.json') b = nib.Bunch(infile=json_pth, otherthing='blue', yat=True) newbdict, bhash = b._get_bunch_hash() assert bhash == 'ddcc7b4ec5675df8cf317a48bd1857fa' # Make sure the hash stored in the json file for `infile` is correct. jshash = nib.md5() with open(json_pth, 'r') as fp: jshash.update(fp.read().encode('utf-8')) assert newbdict['infile'][0][1] == jshash.hexdigest() assert newbdict['yat'] == True
def test_bunch_hash(): # NOTE: Since the path to the json file is included in the Bunch, # the hash will be unique to each machine. pth = os.path.split(os.path.abspath(__file__))[0] json_pth = os.path.join(pth, 'realign_json.json') b = nib.Bunch(infile=json_pth, otherthing='blue', yat=True) newbdict, bhash = b._get_bunch_hash() yield assert_equal, bhash, 'ddcc7b4ec5675df8cf317a48bd1857fa' # Make sure the hash stored in the json file for `infile` is correct. jshash = nib.md5() fp = file(json_pth) jshash.update(fp.read()) fp.close() yield assert_equal, newbdict['infile'][0][1], jshash.hexdigest() yield assert_equal, newbdict['yat'], True
def test_bunch_repr(): b = nib.Bunch(b=2, c=3, a=dict(n=1, m=2)) assert repr(b) == "Bunch(a={'m': 2, 'n': 1}, b=2, c=3)"
def test_bunch_attribute(): b = nib.Bunch(a=1, b=[2, 3], c=None) assert b.a == 1 assert b.b == [2, 3] assert b.c is None
def test_bunch(args): b = nib.Bunch(**args) assert b.__dict__ == args
def test_bunch_repr(): b = nib.Bunch(b=2, c=3, a=dict(n=1, m=2)) yield assert_equal, repr(b), "Bunch(a={'m': 2, 'n': 1}, b=2, c=3)"
def test_bunch_attribute(): b = nib.Bunch(a=1, b=[2, 3], c=None) yield assert_equal, b.a, 1 yield assert_equal, b.b, [2, 3] yield assert_equal, b.c, None
def test_bunch(): b = nib.Bunch() yield assert_equal, b.__dict__, {} b = nib.Bunch(a=1, b=[2, 3]) yield assert_equal, b.__dict__, {'a': 1, 'b': [2, 3]}