示例#1
0
 def test_append_hash(self):
     """
     Tests append_hash functionality. Makes sure all vertices have a hash value.
     """
     data, edges = _gen_simple_dag()
     build_block_dag(data, edges, _hashfunc, append_hashes=True)
     for _, val in data.items():
         self.assertIsNotNone(val["hash"])
示例#2
0
 def test_no_hashfunction(self):
     """
     Tests invocation with no hash function supplied (uses default).
     """
     data, edges = _gen_simple_dag()
     sig_1 = build_block_dag(data, edges)
     sig_2 = build_block_dag(data, edges, _hashfunc)
     self.assertEqual(sig_1["signature"], sig_2["signature"])
示例#3
0
 def test_append_hash_preexisting(self):
     """
     Tests append_hash functionality and that append_hashes overwrites pre-existing values.
     """
     data, edges = _gen_simple_dag()
     sig = build_block_dag(data, edges, _hashfunc, append_hashes=True)
     data["a"]["data"] = [5, 6, 7, 8]
     sig_2 = build_block_dag(data, edges, _hashfunc, append_hashes=True)
     self.assertNotEqual(sig["signature"], sig_2["signature"])
示例#4
0
 def test_changed_names(self):
     """
     Tests two DAGs with the same structured but different key names.
     Should produce identical signatures.
     """
     data_1, edges_1 = _gen_simple_dag()
     data_2, _ = _gen_simple_dag()
     data_2["ab"] = data_2.pop("b")
     data_2["ba"] = data_2.pop("a")
     edges_2 = [("ba", "ab"), ("ba", "c"), ("ab", "d"), ("c", "d")]
     sig_1 = build_block_dag(data_1, edges_1, _hashfunc)
     sig_2 = build_block_dag(data_2, edges_2, _hashfunc)
     self.assertEqual(sig_1["signature"], sig_2["signature"])
示例#5
0
 def test_empty(self):
     """
     Tests a completely empty DAG
     """
     data = {}
     edges = []
     sig = build_block_dag(data, edges, _hashfunc)
     self.assertEqual({"signature": None}, sig)
示例#6
0
 def test_filter_to_empty(self):
     """
     Tests a DAG that is filtered to nothing.
     """
     data, edges = _gen_simple_dag()
     sig = build_block_dag(data, edges, _hashfunc, ["non_field"])
     sig.pop("signature")
     for _, sig_val in sig.items():
         self.assertIsNone(sig_val["data_hash"])
示例#7
0
 def test_simple_empty(self):
     """
     Tests a dag that is filtered with no fields. Should return None as signature.
     """
     data, edges = _gen_simple_dag()
     sig = build_block_dag(data, edges, _hashfunc, [])
     sig.pop("signature")
     for _, sig_val in sig.items():
         self.assertIsNone(sig_val["data_hash"])
示例#8
0
 def test_simple_filtered(self):
     """
     Makes sure that inclusive filtering works
     """
     data, edges = _gen_simple_dag()
     sig = build_block_dag(data, edges, _hashfunc, ["data"])
     self.assertIsNone(sig["d"]["data_hash"])
     for key in ["a", "b", "c"]:
         self.assertIsNotNone(sig[key]["data_hash"])
示例#9
0
 def test_simple_unfiltered(self):
     """
     A simple test accepting all data in the generated DAG.
     """
     data, edges = _gen_simple_dag()
     sig = build_block_dag(data, edges, _hashfunc)
     sig.pop("signature")
     for _, sig_val in sig.items():
         self.assertIsNotNone(sig_val["data_hash"])
示例#10
0
 def test_multiple_parents(self):
     """
     Tests a DAG with multiple identical parents. Parents hashes should append and not be a set.
     """
     data, edges = _gen_simple_dag()
     data["e"] = data["a"].copy()
     edges.append(("e", "b"))
     sig = build_block_dag(data, edges, _hashfunc, ["data"])
     self.assertEqual(sig["a"]["hash"], sig["e"]["hash"])
     self.assertEqual(2, len(sig["b"]["parent_hashes"]))
示例#11
0
def _main():
    data = {
        "a": {"data": 3, "important": [1, 2], "not_data": "help"},
        "b": {"data": "secrets"},
        "c": {"data": [1, "two", 3], "important": [4, 5]},
        "d": {"not_data": "help"},
    }
    edges = [("a", "c"), ("b", "c"), ("b", "d"), ("c", "d")]
    sig = build_block_dag(data, edges, _hashfunc, ["data", "important"])
    print(pretty_prints(data, edges, sig))
示例#12
0
def _main():
    data_1 = {
        "a": {
            "data": 4
        },
        "b": {
            "data": "potato"
        },
        "c": {
            "data": [1, 2, "three", [4]]
        },
        "d": {
            "not_data": 4
        },
    }
    edges_1 = [("a", "b"), ("a", "c"), ("b", "d"), ("c", "d")]
    data_2 = {
        "a": {
            "data": 4
        },
        "b": {
            "data": "potato"
        },
        "c": {
            "data": [1, 23, "three", [4]]
        },
        "d": {
            "not_data": 5
        },
    }
    edges_2 = [("a", "b"), ("a", "c"), ("b", "d"), ("c", "d")]
    sig_1 = build_block_dag(data_1, edges_1, _hashfunc, ["data"])
    sig_2 = build_block_dag(data_2, edges_2, _hashfunc, ["data"])
    dags_same, diff_1, diff_2 = compare_dags(sig_1, sig_2)
    if not dags_same:
        print(diff_1)
        print(diff_2)
示例#13
0
def _main():
    data = {
        "a": {
            "data": 3
        },
        "b": {
            "data": "stringy_string"
        },
        "c": {
            "data": [1, 2, "three", [4, 5]]
        },
        "d": {
            "not_data": None
        },
    }
    edges = [("a", "b"), ("a", "c"), ("b", "d"), ("c", "d")]
    sig = build_block_dag(data,
                          edges,
                          data_fields=["data"],
                          append_hashes=True)
    print(pretty_prints(data, edges, sig))
示例#14
0
def _main():
    data, edges = _binomial_tree(15)
    print(f"{len(data)} vertices\n{len(edges)} edges")
    sig = build_block_dag(data, edges, _hashfunc, ["data", "important"])
    print(pretty_prints(data, edges, sig))