Ejemplo n.º 1
0
def parseModel(contents):
    model = Model()

    for line in contents.split("\n"):
        if line == "" or line.startswith('#'):
            continue

        if line.startswith("@") and ":" in line:
            line = line.replace("@", "")
            key, val = line.split(":", 1)

            if key == "title":
                model.title = val.strip()

            continue

        if line.startswith("\t"):
            line = line.strip().replace("\t", "")

            if "->" in line:
                parseConnection(model, line)
                continue

            if ":" in line:
                parsePersonProperty(model, line)
                continue

            logging.warning("Cannot parse line: %s", line)

        model.addPerson(line)

    return model
Ejemplo n.º 2
0
    def test_add_connection(self):
        m = Model();

        self.assertTrue(len(m.edges) == 0)

        m.addPerson("Alice")
        m.addPerson("Bob")
        m.addConnection("loves", "Alice")

        self.assertTrue(len(m.edges) == 1)
Ejemplo n.º 3
0
    def test_find_by_id(self):
        m = Model()

        m.addPerson("Dave")
        m.lastPerson.setAttribute("id", "superman")

        self.assertTrue(m.findPerson(Person.getDotNodeNameFromFullName("Dave")) is not None)
        self.assertTrue(m.findPerson(Person.getDotNodeNameFromFullName("superman")) is not None)

        with self.assertRaises(Exception):
            m.findPerson(Person.getDotNodeNameFromFullName("superted"))
Ejemplo n.º 4
0
    def test_add_and_find_person(self):
        m = Model()
        
        assert len(m.people) == 0

        m.addPerson("Dave")

        assert len(m.people) == 1

        with self.assertRaises(Exception):
            m.findPerson(Person.getDotNodeNameFromFullName("Gwendelina"))

        assert m.findPerson(Person.getDotNodeNameFromFullName("Dave")) is not None