Exemplo n.º 1
0
graph.write_on_node(u"m3", [u"c1", u"c3", u"c4"], [u"p2", u"p3"],{})
graph.write_on_node(u"P1", [u"p2", u"p3"],[],{})

#printing some predecessors or successors
print graph.get_predecessors(u"m1")
print graph.get_successors(u"m1")
print graph.get_predecessors(u"p2")
print graph.get_successors(u"p2")
print graph.get_successors(u"c3")
print graph.get_successors(graph.root)
print graph.get_predecessors(u"c3")

#getting an attributs list
print graph.get_attributs_list(u'm2')
#getting some attribut
print graph.get_attribut(u'm2', u'guido')
print graph.get_attribut(u'm1', u'jack')

#example of write off (suppression of some elements of a node, like predecessors, successors or attributs)
#getting the elements before
print graph.get_attributs_list(u'm2')
print graph.get_predecessors(u"m2")
print graph.get_successors("m2")

#removing the elements
graph.write_off_node(u"m2", [u"c1"], [u"p2", u"p3"],[u'sape'])

#getting the elements after
print graph.get_attributs_list(u'm2')
print graph.get_predecessors(u"m2")
print graph.get_successors(u"m2")
def main():
    logging.basicConfig(format = '%(levelname)s %(message)s')
    logger = logging.getLogger('redis')
    logger.parent.setLevel(logging.ERROR)

    #creating the graph object
    graph = Directed_graph(r_server, 'uniq', logger, has_root = True)

    RED = '\033[91m'
    ORANGE = '\033[93m'
    GREEN = '\033[92m'

    #adding some nodes
    node1 = 'level_1_1'
    node2 = 'level_1_2'
    node3 = 'level_2_1'
    node4 = 'level_2_2'
    node5 = 'level_3_1'

    node1_predecessors = []
    node1_successors = [node3,node4]

    node2_predecessors = []
    node2_successors = [node3,node4]

    node3_predecessors = [node1,node2]
    node3_successors = [node5]

    node4_predecessors = [node1,node2]
    node4_successors = [node5]

    node5_predecessors = []
    node5_successors = []

    def clean():
        graph.remove_node(node1)
        graph.remove_node(node2)
        graph.remove_node(node3)
        graph.remove_node(node4)
        graph.remove_node(node5)
        graph.remove_node(graph.root)

    def print_test(got,expected,node,nature):
        if got != expected:
            print(RED + "ERROR: "+ node + " " + nature +" is not as it should be")
            print(ORANGE +"GOT:")
            print(got )
            print("EXPECTED:")
            print(expected )
            clean()
            return 1
        else:
            print(GREEN + node + " " + nature +": Ok")


    attributes1 = {'☭jack': set(['1','2']), 'spare☭': '☭youpi'}
    attributes2 = {'jacko': set(['1','2','test']), 'spare☭': '☭youpi', 'bip' : 'bip', 'bip' : 'bop'}
    attributes3 = {'☭jack': set(['1','2']), 'spare☭': '☭youpi'}
    attributes4 = {'☭jack': set(['1','2']), 'spare☭': '☭youpi'}
    attributes5 = {'jacko': set(['1','2','test']), 'spare☭': '☭youpi', 'bip' : 'bip'}
 #
    graph.write_on_node(node3, node3_successors, node3_predecessors, attributes3)
    graph.write_on_node(node4, node4_successors, node4_predecessors, attributes4)
    graph.write_on_node(node1, node1_successors, node1_predecessors, attributes1)
    graph.write_on_node(node2, node2_successors, node2_predecessors, attributes2)
    graph.write_on_node(node5, node5_successors, node5_predecessors, attributes5)
 
    #printing some attributs list
    name = graph.root
    got = graph.get_attributs_list(name)
    expected = set([]) 
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node1
    got = graph.get_attributs_list(name)
    expected = convert(set(['spare☭', '☭jack']))

    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node2
    got = graph.get_attributs_list(name)
    expected = convert({'jacko', 'spare☭', 'bip'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node3
    got = graph.get_attributs_list(name)
    expected = convert({'☭jack', 'spare☭'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node4
    got = graph.get_attributs_list(name)
    expected = convert({'☭jack', 'spare☭'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node5
    got = graph.get_attributs_list(name)
    expected = convert({'jacko', 'spare☭', 'bip'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node5
    got = graph.get_attributs_list(name)
    expected = convert({'jacko', 'spare☭', 'bip'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node5
    got = graph.get_attribut(name,'jacko')
    expected =  convert(set(['1','2','test'] ))
    if print_test(got, expected, name, "attribut") == 1:
        return 1
    
    name = node5
    got = graph.get_attribut(name,'spare☭')
    expected =  convert('☭youpi')
    if print_test(got, expected, name, "attribut") == 1:
        return 1

    clean()

    print(GREEN + "printing attributs list after cleaning (must be empty)")

    #printing some attributs list after clean 
    name = graph.root
    got = graph.get_attributs_list(name)
    expected = set([]) 
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node1
    got = graph.get_attributs_list(name)
    expected = set([])

    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node2
    got = graph.get_attributs_list(name)
    expected = set([]) 
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node3
    got = graph.get_attributs_list(name)
    expected = set([]) 
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node4
    got = graph.get_attributs_list(name)
    expected = set([]) 
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node5
    got = graph.get_attributs_list(name)
    expected = set([]) 
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1
 
    name = node5
    got = graph.get_attribut(name,'spare☭')
    expected =  None
    if print_test(got, expected, name, "attribut") == 1:
        return 1
 


    return 0
def main():
    logging.basicConfig(format='%(levelname)s %(message)s')
    logger = logging.getLogger('redis')
    logger.parent.setLevel(logging.ERROR)

    #creating the graph object
    graph = Directed_graph(r_server, 'uniq', logger, has_root=True)

    RED = '\033[91m'
    ORANGE = '\033[93m'
    GREEN = '\033[92m'

    #adding some nodes
    node1 = 'level_1_1'
    node2 = 'level_1_2'
    node3 = 'level_2_1'
    node4 = 'level_2_2'
    node5 = 'level_3_1'

    node1_predecessors = []
    node1_successors = [node3, node4]

    node2_predecessors = []
    node2_successors = [node3, node4]

    node3_predecessors = [node1, node2]
    node3_successors = [node5]

    node4_predecessors = [node1, node2]
    node4_successors = [node5]

    node5_predecessors = []
    node5_successors = []

    def clean():
        graph.remove_node(node1)
        graph.remove_node(node2)
        graph.remove_node(node3)
        graph.remove_node(node4)
        graph.remove_node(node5)
        graph.remove_node(graph.root)

    def print_test(got, expected, node, nature):
        if got != expected:
            print(RED + "ERROR: " + node + " " + nature +
                  " is not as it should be")
            print(ORANGE + "GOT:")
            print(got)
            print("EXPECTED:")
            print(expected)
            clean()
            return 1
        else:
            print(GREEN + node + " " + nature + ": Ok")

    attributes1 = {'☭jack': set(['1', '2']), 'spare☭': '☭youpi'}
    attributes2 = {
        'jacko': set(['1', '2', 'test']),
        'spare☭': '☭youpi',
        'bip': 'bip',
        'bip': 'bop'
    }
    attributes3 = {'☭jack': set(['1', '2']), 'spare☭': '☭youpi'}
    attributes4 = {'☭jack': set(['1', '2']), 'spare☭': '☭youpi'}
    attributes5 = {
        'jacko': set(['1', '2', 'test']),
        'spare☭': '☭youpi',
        'bip': 'bip'
    }
    #
    graph.write_on_node(node3, node3_successors, node3_predecessors,
                        attributes3)
    graph.write_on_node(node4, node4_successors, node4_predecessors,
                        attributes4)
    graph.write_on_node(node1, node1_successors, node1_predecessors,
                        attributes1)
    graph.write_on_node(node2, node2_successors, node2_predecessors,
                        attributes2)
    graph.write_on_node(node5, node5_successors, node5_predecessors,
                        attributes5)

    #printing some attributs list
    name = graph.root
    got = graph.get_attributs_list(name)
    expected = set([])
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node1
    got = graph.get_attributs_list(name)
    expected = convert(set(['spare☭', '☭jack']))

    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node2
    got = graph.get_attributs_list(name)
    expected = convert({'jacko', 'spare☭', 'bip'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node3
    got = graph.get_attributs_list(name)
    expected = convert({'☭jack', 'spare☭'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node4
    got = graph.get_attributs_list(name)
    expected = convert({'☭jack', 'spare☭'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node5
    got = graph.get_attributs_list(name)
    expected = convert({'jacko', 'spare☭', 'bip'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node5
    got = graph.get_attributs_list(name)
    expected = convert({'jacko', 'spare☭', 'bip'})
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node5
    got = graph.get_attribut(name, 'jacko')
    expected = convert(set(['1', '2', 'test']))
    if print_test(got, expected, name, "attribut") == 1:
        return 1

    name = node5
    got = graph.get_attribut(name, 'spare☭')
    expected = convert('☭youpi')
    if print_test(got, expected, name, "attribut") == 1:
        return 1

    clean()

    print(GREEN + "printing attributs list after cleaning (must be empty)")

    #printing some attributs list after clean
    name = graph.root
    got = graph.get_attributs_list(name)
    expected = set([])
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node1
    got = graph.get_attributs_list(name)
    expected = set([])

    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node2
    got = graph.get_attributs_list(name)
    expected = set([])
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node3
    got = graph.get_attributs_list(name)
    expected = set([])
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node4
    got = graph.get_attributs_list(name)
    expected = set([])
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node5
    got = graph.get_attributs_list(name)
    expected = set([])
    if print_test(got, expected, name, "attributs_list") == 1:
        return 1

    name = node5
    got = graph.get_attribut(name, 'spare☭')
    expected = None
    if print_test(got, expected, name, "attribut") == 1:
        return 1

    return 0
Exemplo n.º 4
0
graph.write_on_node("m3", ["c1", "c3", "c4"], ["p2", "p3"], {})
graph.write_on_node("P1", ["p2", "p3"], [], {})

#printing some predecessors or successors
print(graph.get_predecessors("m1"))
print(graph.get_successors("m1"))
print(graph.get_predecessors("p2"))
print(graph.get_successors("p2"))
print(graph.get_successors("c3"))
print(graph.get_successors(graph.root))
print(graph.get_predecessors("c3"))

#getting an attributs list
print(graph.get_attributs_list('m2'))
#getting some attribut
print(graph.get_attribut('m2', 'guido'))
print(graph.get_attribut('m1', 'jack'))

#example of write off (suppression of some elements of a node, like predecessors, successors or attributs)
#getting the elements before
print(graph.get_attributs_list('m2'))
print(graph.get_predecessors("m2"))
print(graph.get_successors("m2"))

#removing the elements
graph.write_off_node("m2", ["c1"], ["p2", "p3"], ['sape'])

#getting the elements after
print(graph.get_attributs_list('m2'))
print(graph.get_predecessors("m2"))
print(graph.get_successors("m2"))
Exemplo n.º 5
0
graph.write_on_node("m3", ["c1", "c3", "c4"], ["p2", "p3"],{})
graph.write_on_node("P1", ["p2", "p3"],[],{})

#printing some predecessors or successors
print(graph.get_predecessors("m1"))
print(graph.get_successors("m1"))
print(graph.get_predecessors("p2"))
print(graph.get_successors("p2"))
print(graph.get_successors("c3"))
print(graph.get_successors(graph.root))
print(graph.get_predecessors("c3"))

#getting an attributs list
print(graph.get_attributs_list('m2'))
#getting some attribut
print(graph.get_attribut('m2', 'guido'))
print(graph.get_attribut('m1', 'jack'))

#example of write off (suppression of some elements of a node, like predecessors, successors or attributs)
#getting the elements before
print(graph.get_attributs_list('m2'))
print(graph.get_predecessors("m2"))
print(graph.get_successors("m2"))

#removing the elements
graph.write_off_node("m2", ["c1"], ["p2", "p3"],['sape'])

#getting the elements after
print(graph.get_attributs_list('m2'))
print(graph.get_predecessors("m2"))
print(graph.get_successors("m2"))