Exemplo n.º 1
0
 def hash(self):
     m = hashlib.sha1()
     m.update(util.prepare_for_hash(self.__class__.__name__))
     m.update(
         util.prepare_for_hash(str(util.standardize(self.domain_shape))))
     m.update(util.prepare_for_hash(str(util.standardize(
         self.prefix_axes))))
     return m.hexdigest()
Exemplo n.º 2
0
 def test_json_primitives(self):
     self.assertEqual(13, serde(13))
     self.assertEqual(True, serde(True))
     self.assertEqual(3.14, serde(3.14))
     self.assertEqual('test', serde('test')) 
     self.assertEqual(u'test', serde(u'test')) 
     self.assertEqual(OrderedDict({'a': 1}), 
                      serde(OrderedDict({'a': 1})))
     self.assertEqual(util.standardize((3,2)), 
                      util.standardize(serde((3,2))))
     self.assertEqual(['a', 'b'], serde(['a', 'b']))
     self.assertEqual(None, serde(None))
Exemplo n.º 3
0
    def test_json_hierarchical(self):
        d1 = {'a': self.A,
              'b': {'b1': self.A,
                    'b2': {'b21': self.A}},
              'c': [self.A]}

        self.assertEqual(d1['a'].hash, serde(d1)['a'].hash)
        self.assertEqual(d1['b']['b1'].hash, serde(d1)['b']['b1'].hash)
        self.assertEqual(d1['b']['b2']['b21'].hash, serde(d1)['b']['b2']['b21'].hash)
        self.assertEqual(d1['c'][0].hash, serde(d1)['c'][0].hash)

        d2 = {1: np.ones((3,2)),
              2: {21: np.ones((5,4)),
                  22: {221: np.ones((13,2))}}}

        self.assertEqual(util.standardize(d2), util.standardize(serde(d2)))
Exemplo n.º 4
0
 def hash(self):
     """
     Uniqueness of this hash relies on subclasses writing init parameters as instance variables
     """
     m = hashlib.sha1()
     m.update(util.prepare_for_hash(self.__class__.__name__))
     m.update(util.prepare_for_hash(str(util.standardize(sorted(self.init_params.items())))))
     return m.hexdigest()
Exemplo n.º 5
0
    def test_json_mixed(self):
        d = {'a': 13,
             5: 3.14,
             (1,2): np.ones((3,2))}

        self.assertEqual(util.standardize(d), util.standardize(serde(d)))
Exemplo n.º 6
0
 def test_json_numpy_array(self):
     self.assertEqual(util.standardize(np.ones((3,2))), 
                      util.standardize(serde(np.ones((3,2)))))