コード例 #1
0
ファイル: test_goanna_core.py プロジェクト: shawnchin/goanna
    def test_basic_query(self):
        g = self.goanna

        # query unknown data
        self.assertEqual(g.query_range("p0"), [])
        self.assertEqual(g.query_range("p0", "b0"), [])
        self.assertEqual(g.query_latest("p0"), None)
        self.assertEqual(g.query_latest("p0", "b0"), None)

        # add change
        c = Change("r123", "lsc", "This is a fake commit", [
            "/hello/world/.",
            "/hello/world/test.txt",
            "/hello/kitty/is/too_pink.com",
            "/donny/darko/.now",
            "/he/.",
        ], "project")
        g.post_changes(c)

        # this should not affect unknown projects
        self.assertEqual(g.query_latest("p0"), None)

        # query for latest change
        self.assertEqual(g.query_latest("project")[0], "r123")
        self.assertEqual(g.query_latest("project", None)[0], "r123")
        self.assertEqual(g.query_latest("project", "nobranch"), None)

        self.assertTrue(utils.unpack(g.query_latest("project", details=True)),
                        c.get_data())
        ts0 = g.query_latest("project")[1]

        sleep(0.05)  # sleep a while so we get a different timestamp
        # add multiple changes
        changes = [
            Change("897", "lsc", "commit", ["/", "/a"], "p0", "b0"),
            Change("s91", "djw", "comment", "/", "project"),
            Change("deadbeef", "root", "none", "/world", "p2", "b2"),
        ]
        g.post_changes(changes)
        self.assertEqual(g.query_latest("project", None)[0], "s91")

        ts1 = g.query_latest("project")[1]
        self.assertNotEqual(ts0, ts1)

        self.assertEqual(g.query_range("project", ts_upper=ts0), [])
        self.assertEqual(g.query_range("project", ts_lower=ts1), [])
        self.assertEqual(g.query_range("project", ts_lower=ts0), ["s91"])
        self.assertEqual(g.query_range("project", ts_upper=ts1), ["r123"])
        self.assertEqual(g.query_range("project"), ["r123", "s91"])

        r_list = g.query_range("project", details=True)
        self.assertTrue(utils.unpack(r_list[0]), c.get_data())
        self.assertTrue(utils.unpack(r_list[0]), changes[1].get_data())

        # test packing of list of Change instance
        packed_data = Goanna.pack_list_of_changes(changes)
        changes_2 = Goanna.unpack_list_of_changes(packed_data)
        self.assertEqual(changes, changes_2)
コード例 #2
0
ファイル: test_goanna_core.py プロジェクト: shawnchin/goanna
    def test_pack_unpack(self):
        c = Change("r123", "lsc", "This is a fake commit", [
            "/hello/world/.",
            "/hello/world/test.txt",
            "/hello/kitty/is/too_pink.com",
            "/donny/darko/.now",
            "/he/.",
        ], "project")

        packed_data = c.packed()
        c2 = Change.from_packed(packed_data)
        self.assertEqual(c.data, c2.data)
コード例 #3
0
ファイル: test_goanna_core.py プロジェクト: shawnchin/goanna
    def test_affected_path_detection(self):
        c = Change("r123", "lsc", "This is a fake commit", [
            "/hello/world/.",
            "/hello/world/test.txt",
            "/hello/kitty/is/too_pink.com",
            "/donny/darko/.now",
            "/he/.",
        ], "project")

        self.assertEqual(c.filter_paths_affected_by_change([]), [])
        self.assertEqual(c.filter_paths_affected_by_change(["/"]), ["/"])
        self.assertEqual(c.filter_paths_affected_by_change(["/a"]), [])

        self.assertEqual(c.filter_paths_affected_by_change([
            "/a",
            "/hello/world",
            "/helio",
            "/donny/darko/was/strange",
            "/",
        ]), ["/", "/hello/world"])

        self.assertEqual(c.filter_paths_affected_by_change([
            "/a",
            "/helio",
            "/donny/lighto"
        ]), [])