Exemplo n.º 1
0
    def test_1root_1child(self):
        lines = [
            "NODE_1_1[...,...]",
            "\t->NODE_1_2[...,...]",
        ]
        parser = Parser()
        graph = Graph()

        graph.build(parser, lines)

        self.assertEqual(2, len(graph.nodes()))
        self.assertEqual(1, len(graph.roots()))
        self.assertEqual(1, len(graph.tails()))
Exemplo n.º 2
0
    def test_2root_3child(self):
        lines = [
            "NODE_1_1[...,...]",
            "\t->NODE_1_2[...,...]",
            "\t->\t  NODE_1_3[...,...]",
            "\t->NODE_1_4[...,...]",
            "NODE_2_1[...,...]",
        ]
        parser = Parser()
        graph = Graph()

        graph.build(parser, lines)

        self.assertEqual(5, len(graph.nodes()))
        self.assertEqual(2, len(graph.roots()))
        self.assertEqual(3, len(graph.tails()))
Exemplo n.º 3
0
  def test_1root_1child(self):
    lines = [
      "NODE_1_1[...,...]",
      "\t->NODE_1_2[...,...]",
    ]
    parser = Parser()
    graph = Graph()

    graph.build(parser, lines)

    self.assertEqual(2, len(graph.nodes()))
    self.assertEqual(1, len(graph.roots()))
    self.assertEqual(1, len(graph.tails()))
Exemplo n.º 4
0
  def test_2root_3child(self):
    lines = [
      "NODE_1_1[...,...]",
      "\t->NODE_1_2[...,...]",
      "\t->\t  NODE_1_3[...,...]",
      "\t->NODE_1_4[...,...]",
      "NODE_2_1[...,...]",
    ]
    parser = Parser()
    graph = Graph()

    graph.build(parser, lines)

    self.assertEqual(5, len(graph.nodes()))
    self.assertEqual(2, len(graph.roots()))
    self.assertEqual(3, len(graph.tails()))
Exemplo n.º 5
0
# Copyright (c) 2020, 2021 Jean-Sebastien Gelinas, see LICENSE at the root of the repository

import sys

from parsing.parser import Parser
from parsing.graph import Graph

file_path = sys.argv[1]
file = open(file_path)

print("Reading from '{}'".format(file_path))

parser = Parser()
graph = Graph()
try:
    stats = graph.build(parser, file, skip_until="Done building lattice!")

    print(" -> Processed {} out of {} lines (skipped {}, parsed {})".format(
        stats['nb_parsed'] + stats['nb_skipped'],
        stats['nb_read'],
        stats['nb_skipped'],
        stats['nb_parsed'],
    ))
    print(" -> Found {} nodes ({} roots, {} tails)".format(
        stats['nb_nodes'],
        stats['nb_roots'],
        stats['nb_tails'],
    ))
finally:
    file.close()
Exemplo n.º 6
0
def parse(file):
  parser = Parser()
  graph = Graph()
  stats = graph.build(parser, file, skip_until="Done building lattice!")
  return graph, stats
Exemplo n.º 7
0
  ))
  print(" ---> Found {} nodes ({} roots, {} tails)".format(
    stats['nb_nodes'],
    stats['nb_roots'],
    stats['nb_tails'],
  ))

  graphs = [first, second]

finally:
  files[0].close()
  files[1].close()

# Compare !
different_childs = []
different_parents = []

def on_difference(nodeid, node_before, node_after):
  if node_before.childs().keys() != node_after.childs().keys():
    different_childs.append(nodeid)
  if node_before.parents().keys() != node_after.parents().keys():
    different_parents.append(nodeid)

stats, only_before, only_after, equal_in_both = Graph.compare(graphs[0], graphs[1], on_difference)
print ("Found {} nodes only in the first file".format(stats['nb_nodes_only_before']))
print ("Found {} nodes only in the second file".format(stats['nb_nodes_only_after']))
print ("Found {} nodes in common between both files".format(stats['nb_nodes_in_common']))
print ("Found {} common nodes with a difference in parents definition".format(len(different_parents)))
print ("Found {} common nodes with a difference in childs definition".format(len(different_childs)))

Exemplo n.º 8
0
def parse(file):
    parser = Parser()
    graph = Graph()
    stats = graph.build(parser, file, skip_until="Done building lattice!")
    return graph, stats
Exemplo n.º 9
0
    graphs = [first, second]

finally:
    files[0].close()
    files[1].close()

# Compare !
different_childs = []
different_parents = []


def on_difference(nodeid, node_before, node_after):
    if node_before.childs().keys() != node_after.childs().keys():
        different_childs.append(nodeid)
    if node_before.parents().keys() != node_after.parents().keys():
        different_parents.append(nodeid)


stats, only_before, only_after, equal_in_both = Graph.compare(
    graphs[0], graphs[1], on_difference)
print("Found {} nodes only in the first file".format(
    stats['nb_nodes_only_before']))
print("Found {} nodes only in the second file".format(
    stats['nb_nodes_only_after']))
print("Found {} nodes in common between both files".format(
    stats['nb_nodes_in_common']))
print("Found {} common nodes with a difference in parents definition".format(
    len(different_parents)))
print("Found {} common nodes with a difference in childs definition".format(
    len(different_childs)))