コード例 #1
0
ファイル: calendar_test.py プロジェクト: mpetyx/py2neo
class TestDateRanges(unittest.TestCase):

    def setUp(self):
        self.calendar = GregorianCalendar(TIME)

    def test_can_get_date_range(self):
        xmas_year = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert isinstance(xmas_year, neo4j.Node)
        assert xmas_year["start_date"] == "2000-12-25"
        assert xmas_year["end_date"] == "2001-12-25"
        rels = xmas_year.get_relationships(neo4j.Direction.OUTGOING, "START_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)
        rels = xmas_year.get_relationships(neo4j.Direction.OUTGOING, "END_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2001, 12, 25))
        assert rels[0].end_node == self.calendar.day(2001, 12, 25)

    def test_will_always_get_same_date_range_node(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert range1 == range2

    def test_can_get_different_date_range_nodes(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 1, 1), (2000, 12, 31))
        assert range1 != range2

    def test_single_day_range(self):
        range = self.calendar.date_range((2000, 12, 25), (2000, 12, 25))
        assert range == self.calendar.day(2000, 12, 25)

    def test_range_within_month(self):
        advent = self.calendar.date_range((2000, 12, 1), (2000, 12, 24))
        rels = advent.get_relationships(neo4j.Direction.INCOMING, "DATE_RANGE")
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.month(2000, 12)
        rels = advent.get_relationships(neo4j.Direction.OUTGOING, "START_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 1))
        assert rels[0].end_node == self.calendar.day(2000, 12, 1)
        rels = advent.get_relationships(neo4j.Direction.OUTGOING, "END_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)

    def test_range_within_year(self):
        range = self.calendar.date_range((2000, 4, 10), (2000, 12, 24))
        rels = range.get_relationships(neo4j.Direction.INCOMING, "DATE_RANGE")
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.year(2000)
        rels = range.get_relationships(neo4j.Direction.OUTGOING, "START_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 4, 10))
        assert rels[0].end_node == self.calendar.day(2000, 4, 10)
        rels = range.get_relationships(neo4j.Direction.OUTGOING, "END_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)
コード例 #2
0
class TestYears(unittest.TestCase):
    def setUp(self):
        self.calendar = GregorianCalendar(TIME)

    def test_can_get_year_node(self):
        millennium = self.calendar.year(2000)
        assert isinstance(millennium, neo4j.Node)
        assert millennium["year"] == 2000

    def test_will_always_get_same_month_node(self):
        first_millennium = self.calendar.year(2000)
        for i in range(40):
            next_millennium = self.calendar.year(2000)
            assert next_millennium == first_millennium

    def test_can_get_different_year_nodes(self):
        millennium_2000 = self.calendar.year(2000)
        millennium_2001 = self.calendar.year(2001)
        assert millennium_2000 != millennium_2001
コード例 #3
0
ファイル: calendar_test.py プロジェクト: SunPowered/py2neo
class TestYears(unittest.TestCase):

    def setUp(self):
        self.calendar = GregorianCalendar(TIME)

    def test_can_get_year_node(self):
        millennium = self.calendar.year(2000)
        assert isinstance(millennium, neo4j.Node)
        assert millennium["year"] == 2000

    def test_will_always_get_same_month_node(self):
        first_millennium = self.calendar.year(2000)
        for i in range(40):
            next_millennium = self.calendar.year(2000)
            assert next_millennium == first_millennium

    def test_can_get_different_year_nodes(self):
        millennium_2000 = self.calendar.year(2000)
        millennium_2001 = self.calendar.year(2001)
        assert millennium_2000 != millennium_2001
コード例 #4
0
class TestDateRanges(unittest.TestCase):
    def setUp(self):
        clear()
        self.calendar = GregorianCalendar(TIME)

    def test_can_get_date_range(self):
        xmas_year = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert isinstance(xmas_year, neo4j.Node)
        assert xmas_year["start_date"] == "2000-12-25"
        assert xmas_year["end_date"] == "2001-12-25"
        rels = list(xmas_year.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)
        rels = list(xmas_year.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2001, 12, 25))
        assert rels[0].end_node == self.calendar.day(2001, 12, 25)

    def test_will_always_get_same_date_range_node(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert range1 == range2

    def test_can_get_different_date_range_nodes(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 1, 1), (2000, 12, 31))
        assert range1 != range2

    def test_single_day_range(self):
        range_ = self.calendar.date_range((2000, 12, 25), (2000, 12, 25))
        assert range_ == self.calendar.day(2000, 12, 25)

    def test_range_within_month(self):
        advent = self.calendar.date_range((2000, 12, 1), (2000, 12, 24))
        rels = list(advent.match_incoming("DATE_RANGE"))
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.month(2000, 12)
        rels = list(advent.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 1))
        assert rels[0].end_node == self.calendar.day(2000, 12, 1)
        rels = list(advent.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)

    def test_range_within_year(self):
        range_ = self.calendar.date_range((2000, 4, 10), (2000, 12, 24))
        rels = list(range_.match_incoming("DATE_RANGE"))
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.year(2000)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 4, 10))
        assert rels[0].end_node == self.calendar.day(2000, 4, 10)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)

    def test_open_start_range(self):
        range_ = self.calendar.date_range(None, (2000, 12, 25))
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 0
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)

    def test_open_end_range(self):
        range_ = self.calendar.date_range((2000, 12, 25), None)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 0

    def test_no_fully_open_date_range(self):
        try:
            self.calendar.date_range(None, None)
        except ValueError:
            return True
        else:
            return False

    def test_first_quarter(self):
        range_ = self.calendar.quarter(2000, 1)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 1, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 3, 31)

    def test_second_quarter(self):
        range_ = self.calendar.quarter(2000, 2)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 4, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 6, 30)

    def test_third_quarter(self):
        range_ = self.calendar.quarter(2000, 3)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 7, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 9, 30)

    def test_fourth_quarter(self):
        range_ = self.calendar.quarter(2000, 4)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 10, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 12, 31)

    def test_no_fifth_quarter(self):
        try:
            self.calendar.quarter(2000, 5)
        except ValueError:
            return True
        else:
            return False
コード例 #5
0
class TestDateRanges(unittest.TestCase):
    def setUp(self):
        self.calendar = GregorianCalendar(TIME)

    def test_can_get_date_range(self):
        xmas_year = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert isinstance(xmas_year, neo4j.Node)
        assert xmas_year["start_date"] == "2000-12-25"
        assert xmas_year["end_date"] == "2001-12-25"
        rels = xmas_year.get_relationships(neo4j.Direction.OUTGOING,
                                           "START_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)
        rels = xmas_year.get_relationships(neo4j.Direction.OUTGOING,
                                           "END_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2001, 12, 25))
        assert rels[0].end_node == self.calendar.day(2001, 12, 25)

    def test_will_always_get_same_date_range_node(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert range1 == range2

    def test_can_get_different_date_range_nodes(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 1, 1), (2000, 12, 31))
        assert range1 != range2

    def test_single_day_range(self):
        range = self.calendar.date_range((2000, 12, 25), (2000, 12, 25))
        assert range == self.calendar.day(2000, 12, 25)

    def test_range_within_month(self):
        advent = self.calendar.date_range((2000, 12, 1), (2000, 12, 24))
        rels = advent.get_relationships(neo4j.Direction.INCOMING, "DATE_RANGE")
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.month(2000, 12)
        rels = advent.get_relationships(neo4j.Direction.OUTGOING, "START_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 1))
        assert rels[0].end_node == self.calendar.day(2000, 12, 1)
        rels = advent.get_relationships(neo4j.Direction.OUTGOING, "END_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)

    def test_range_within_year(self):
        range = self.calendar.date_range((2000, 4, 10), (2000, 12, 24))
        rels = range.get_relationships(neo4j.Direction.INCOMING, "DATE_RANGE")
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.year(2000)
        rels = range.get_relationships(neo4j.Direction.OUTGOING, "START_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 4, 10))
        assert rels[0].end_node == self.calendar.day(2000, 4, 10)
        rels = range.get_relationships(neo4j.Direction.OUTGOING, "END_DATE")
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)
コード例 #6
0
ファイル: calendar_test.py プロジェクト: SunPowered/py2neo
class TestDateRanges(unittest.TestCase):

    def setUp(self):
        clear()
        self.calendar = GregorianCalendar(TIME)

    def test_can_get_date_range(self):
        xmas_year = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert isinstance(xmas_year, neo4j.Node)
        assert xmas_year["start_date"] == "2000-12-25"
        assert xmas_year["end_date"] == "2001-12-25"
        rels = list(xmas_year.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)
        rels = list(xmas_year.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2001, 12, 25))
        assert rels[0].end_node == self.calendar.day(2001, 12, 25)

    def test_will_always_get_same_date_range_node(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        assert range1 == range2

    def test_can_get_different_date_range_nodes(self):
        range1 = self.calendar.date_range((2000, 12, 25), (2001, 12, 25))
        range2 = self.calendar.date_range((2000, 1, 1), (2000, 12, 31))
        assert range1 != range2

    def test_single_day_range(self):
        range_ = self.calendar.date_range((2000, 12, 25), (2000, 12, 25))
        assert range_ == self.calendar.day(2000, 12, 25)

    def test_range_within_month(self):
        advent = self.calendar.date_range((2000, 12, 1), (2000, 12, 24))
        rels = list(advent.match_incoming("DATE_RANGE"))
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.month(2000, 12)
        rels = list(advent.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 1))
        assert rels[0].end_node == self.calendar.day(2000, 12, 1)
        rels = list(advent.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)

    def test_range_within_year(self):
        range_ = self.calendar.date_range((2000, 4, 10), (2000, 12, 24))
        rels = list(range_.match_incoming("DATE_RANGE"))
        assert len(rels) == 1
        assert rels[0].start_node == self.calendar.year(2000)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 4, 10))
        assert rels[0].end_node == self.calendar.day(2000, 4, 10)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 24))
        assert rels[0].end_node == self.calendar.day(2000, 12, 24)

    def test_open_start_range(self):
        range_ = self.calendar.date_range(None, (2000, 12, 25))
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 0
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)

    def test_open_end_range(self):
        range_ = self.calendar.date_range((2000, 12, 25), None)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.date((2000, 12, 25))
        assert rels[0].end_node == self.calendar.day(2000, 12, 25)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 0

    def test_no_fully_open_date_range(self):
        try:
            self.calendar.date_range(None, None)
        except ValueError:
            return True
        else:
            return False

    def test_first_quarter(self):
        range_ = self.calendar.quarter(2000, 1)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 1, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 3, 31)

    def test_second_quarter(self):
        range_ = self.calendar.quarter(2000, 2)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 4, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 6, 30)

    def test_third_quarter(self):
        range_ = self.calendar.quarter(2000, 3)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 7, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 9, 30)

    def test_fourth_quarter(self):
        range_ = self.calendar.quarter(2000, 4)
        rels = list(range_.match_outgoing("START_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 10, 1)
        rels = list(range_.match_outgoing("END_DATE"))
        assert len(rels) == 1
        assert rels[0].end_node == self.calendar.day(2000, 12, 31)

    def test_no_fifth_quarter(self):
        try:
            self.calendar.quarter(2000, 5)
        except ValueError:
            return True
        else:
            return False