def test_dict_equiv(self): x = OrderedDict() x['a'] = 3 x['b'] = np.array([1, 2, 3]) y = OrderedDict() y['b'] = np.array([1.0, 2.0, 3.0]) y['a'] = 3 self.assertTrue(utils.dict_equiv(x, y)) # two nparrays are equal y['b'] = [1, 2, 3] # np.array not the same as a list self.assertTrue(utils.dict_equiv(x, y)) # nparray == list x['b'] = [1.0, 2.0, 3.0] self.assertTrue(utils.dict_equiv(x, y)) # list vs. list x['c'] = None self.assertFalse(utils.dict_equiv(x, y)) # new key in x x['c'] = np.nan y['c'] = np.nan self.assertTrue(utils.dict_equiv(x, y)) # as intended, nan is nan x['c'] = np.inf y['c'] = np.inf self.assertTrue(utils.dict_equiv(x, y)) # inf == inf y = dict(y) self.assertTrue(utils.dict_equiv( x, y)) # different dictionary types are fine y['b'] = 3 * np.arange(3) self.assertFalse(utils.dict_equiv(x, y)) # not equal when arrays differ
def assertDatasetIdentical(self, d1, d2): # this method is functionally equivalent to `assert d1.identical(d2)`, # but it checks each aspect of equality separately for easier debugging assert utils.dict_equiv(d1.attrs, d2.attrs), (d1.attrs, d2.attrs) self.assertEqual(sorted(d1.vars, key=str), sorted(d2.vars, key=str)) self.assertEqual(sorted(d1.coords, key=str), sorted(d2.coords, key=str)) for k in d1: v1 = d1._arrays[k] v2 = d2._arrays[k] self.assertVariableIdentical(v1, v2)
def test_dict_equiv(self): x = OrderedDict() x['a'] = 3 x['b'] = np.array([1, 2, 3]) y = OrderedDict() y['b'] = np.array([1.0, 2.0, 3.0]) y['a'] = 3 self.assertTrue(utils.dict_equiv(x, y)) # two nparrays are equal y['b'] = [1, 2, 3] # np.array not the same as a list self.assertTrue(utils.dict_equiv(x, y)) # nparray == list x['b'] = [1.0, 2.0, 3.0] self.assertTrue(utils.dict_equiv(x, y)) # list vs. list x['c'] = None self.assertFalse(utils.dict_equiv(x, y)) # new key in x x['c'] = np.nan y['c'] = np.nan self.assertTrue(utils.dict_equiv(x, y)) # as intended, nan is nan x['c'] = np.inf y['c'] = np.inf self.assertTrue(utils.dict_equiv(x, y)) # inf == inf y = dict(y) self.assertTrue(utils.dict_equiv(x, y)) # different dictionary types are fine y['b'] = 3 * np.arange(3) self.assertFalse(utils.dict_equiv(x, y)) # not equal when arrays differ