def test_args(self): """ If a data point has inputs, the lineal hash of the data point is SHA(SHA(SHA(name) + version) + input1_lineal_hash + input2_lineal_hash) """ sample_hash1 = sha1("foo").hexdigest() sample_hash2 = sha1("bar").hexdigest() a = linealHash("name", "version", [sample_hash1, sample_hash2]) expected = sha1(linealHash("name", "version") + sample_hash1 + sample_hash2).hexdigest() self.assertEqual( a, expected, "With inputs, expected lineal hash to be" " H(linealHash + input1hash + input2hash)" )
def test_basic(self): """ The most basic lineal hash is SHA(SHA(name) + version) """ a = linealHash("name", "version") expected = sha1(sha1("name").hexdigest() + "version").hexdigest() self.assertEqual(a, expected)
def _gotValueList(self, values, entity, name, version): values = [x[1] for x in values] dlist = [] for combination in product(*values): lineages = [x.lineage for x in combination] work = Work( entity, name, version, linealHash(name, version, lineages), [IWorkInput(x) for x in combination] ) d = ISource(self).emit(work) dlist.append(d) return aggregateResult(dlist)
def test_IData(self): """ You can easily convert IInput into IData """ i = Input("joe", "a", "1", "value") d = IData(i) self.assertEqual(d.entity, "joe") self.assertEqual(d.name, "a") self.assertEqual(d.version, "1") self.assertEqual(d.value, "value") self.assertEqual(d.lineage, linealHash("a", "1"))
def test_doPossibleWork_multiPath(self): """ If there's data for multiple paths, do work for all paths. """ store, garden, w, recv = self.mkCakeSetup() store.put(Data('sam', 'eggs', '1', 'aaaa', 'eggs value')) store.put(Data('sam', 'flour', '1', 'bbbb', 'flour value')) store.put(Data('sam', 'flour', 'new', 'cccc', 'flour value 2')) r = w.doPossibleWork('sam', 'cake', '1') recv.receive.assert_has_calls([ call(Work('sam', 'cake', '1', linealHash('cake', '1', ['aaaa', 'bbbb']), [('eggs', '1', 'aaaa', 'eggs value'), ('flour', '1', 'bbbb', 'flour value')])), call(Work('sam', 'cake', '1', linealHash('cake', '1', ['aaaa', 'cccc']), [('eggs', '1', 'aaaa', 'eggs value'), ('flour', 'new', 'cccc', 'flour value 2')])), ]) self.assertEqual(recv.receive.call_count, 2) self.assertEqual(len(self.successResultOf(r)), 2)
def test_doPossibleWork_simple(self): """ If there's enough data to do one piece of work, do that. """ store, garden, w, recv = self.mkCakeSetup() store.put(Data('sam', 'eggs', '1', 'aaaa', 'eggs value')) store.put(Data('sam', 'flour', '1', 'bbbb', 'flour value')) r = w.doPossibleWork('sam', 'cake', '1') recv.receive.assert_called_once_with(Work('sam', 'cake', '1', linealHash('cake', '1', ['aaaa', 'bbbb']), [('eggs', '1', 'aaaa', 'eggs value'), ('flour', '1', 'bbbb', 'flour value')] )) self.assertTrue(r.called) return r