Пример #1
0
class GregorianDate(object):
    """ A date picked from a :class:`.GregorianCalendar`.
    """

    #: The calendar from which this date was picked.
    calendar = None

    #: The graph associated with this date.
    graph = None

    #: Full :class:`Path <py2neo.Path>` representing this date.
    path = None

    def __init__(self, calendar, year, month=1, day=1):
        self.calendar = calendar
        self.graph = self.calendar.graph
        self.path = Path(
            self.calendar.root, "YEAR",
            Node("Year", key='%04d' % year, year=year), "MONTH",
            Node("Month",
                 key='%04d-%02d' % (year, month),
                 year=year,
                 month=month), "DAY",
            Node("Day",
                 key='%04d-%02d-%02d' % (year, month, day),
                 year=year,
                 month=month,
                 day=day))
        self.graph.merge(self.path)

    @property
    def year(self):
        """ The year node for this date.

        :rtype: :class:`py2neo.Node`

        """
        return self.path.nodes()[1]

    @property
    def month(self):
        """ The month node for this date.

        :rtype: :class:`py2neo.Node`

        """
        return self.path.nodes()[2]

    @property
    def day(self):
        """ The day node for this date.

        :rtype: :class:`py2neo.Node`

        """
        return self.path.nodes()[3]
Пример #2
0
class GregorianDate(object):
    """ A date picked from a :class:`.GregorianCalendar`.
    """

    #: The calendar from which this date was picked.
    calendar = None

    #: The graph associated with this date.
    graph = None

    #: Full :class:`Path <py2neo.Path>` representing this date.
    path = None

    def __init__(self, calendar, year, month=1, day=1):
        self.calendar = calendar
        self.graph = self.calendar.graph
        self.path = Path(self.calendar.root,
                         "YEAR", Node("Year", key='%04d' % year, year=year),
                         "MONTH", Node("Month", key='%04d-%02d' % (year, month), year=year, month=month),
                         "DAY", Node("Day", key='%04d-%02d-%02d' % (year, month, day), year=year, month=month, day=day))
        self.graph.merge(self.path)

    @property
    def year(self):
        """ The year node for this date.

        :rtype: :class:`py2neo.Node`

        """
        return self.path.nodes()[1]

    @property
    def month(self):
        """ The month node for this date.

        :rtype: :class:`py2neo.Node`

        """
        return self.path.nodes()[2]

    @property
    def day(self):
        """ The day node for this date.

        :rtype: :class:`py2neo.Node`

        """
        return self.path.nodes()[3]
Пример #3
0
 def test_can_create_path(self):
     path = Path({"name": "Alice"}, "KNOWS", {"name": "Bob"})
     nodes = path.nodes()
     assert len(path) == 1
     assert nodes[0]["name"] == "Alice"
     assert path[0].type() == "KNOWS"
     assert nodes[-1]["name"] == "Bob"
     path = Path(path, "KNOWS", {"name": "Carol"})
     nodes = path.nodes()
     assert len(path) == 2
     assert nodes[0]["name"] == "Alice"
     assert path[0].type() == "KNOWS"
     assert nodes[1]["name"] == "Bob"
     path = Path({"name": "Zach"}, "KNOWS", path)
     nodes = path.nodes()
     assert len(path) == 3
     assert nodes[0]["name"] == "Zach"
     assert path[0].type() == "KNOWS"
     assert nodes[1]["name"] == "Alice"
     assert path[1].type() == "KNOWS"
     assert nodes[2]["name"] == "Bob"
Пример #4
0
 def test_can_create_path(self):
     path = Path({"name": "Alice"}, "KNOWS", {"name": "Bob"})
     nodes = path.nodes()
     assert dict(nodes[0]) == {"name": "Alice"}
     assert path[0].type() == "KNOWS"
     assert dict(nodes[1]) == {"name": "Bob"}
     self.graph.create(path)
     assert isinstance(nodes[0], Node)
     assert nodes[0]["name"] == "Alice"
     assert isinstance(path[0], Relationship)
     assert path[0].type() == "KNOWS"
     assert isinstance(nodes[1], Node)
     assert nodes[1]["name"] == "Bob"