예제 #1
0
 def wlockExists(self, subdata, exists):
     norm_wlock = norm_relative_path(".hg/wlock")
     for sub in subdata:
         if "files" not in sub:
             # Don't trip over cancellation notices left over from other
             # tests that ran against this same instance
             continue
         for f in sub["files"]:
             if (f["exists"] == exists
                     and norm_relative_path(f["name"]) == norm_wlock):
                 return True
     return False
예제 #2
0
    def runProjectTests(self, config, expect, touch_watchmanconfig=False):
        with WatchmanInstance.Instance(config=config) as inst:
            inst.start()
            client = self.getClient(inst)

            for touch, expect_watch, expect_rel, expect_pass in expect:
                # encode the test criteria in the dirname so that we can
                # figure out which test scenario failed more easily

                suffix = "-%s-%s-%s-%s" % (touch, expect_watch, expect_rel, expect_pass)
                suffix = suffix.replace("/", "Z")
                d = self.mkdtemp(suffix=suffix)

                dir_to_watch = os.path.join(d, "a", "b", "c")
                os.makedirs(dir_to_watch, 0o777)
                dir_to_watch = norm_absolute_path(dir_to_watch)
                self.touchRelative(d, touch)
                if touch_watchmanconfig:
                    make_empty_watchmanconfig(d)

                if expect_watch:
                    expect_watch = os.path.join(d, expect_watch)
                else:
                    expect_watch = d

                if expect_pass:
                    res = client.query("watch-project", dir_to_watch)

                    self.assertEqual(
                        norm_absolute_path(os.path.join(d, expect_watch)),
                        norm_absolute_path(res["watch"]),
                    )
                    if not expect_rel:
                        self.assertEqual(None, res.get("relative_path"))
                    else:
                        self.assertEqual(
                            norm_relative_path(expect_rel),
                            norm_relative_path(res.get("relative_path")),
                        )
                else:
                    with self.assertRaises(pywatchman.WatchmanError) as ctx:
                        client.query("watch-project", dir_to_watch)
                    self.assertIn(
                        (
                            "None of the files listed in global config "
                            + "root_files are present in path `"
                            + dir_to_watch
                            + "` or any of its parent directories.  "
                            + "root_files is defined by the"
                        ),
                        str(ctx.exception),
                    )
예제 #3
0
 def wlockExists(self, subdata, exists):
     norm_wlock = norm_relative_path(".hg/wlock")
     for sub in subdata:
         if "files" not in sub:
             # Don't trip over cancellation notices left over from other
             # tests that ran against this same instance
             continue
         for f in sub["files"]:
             if (
                 f["exists"] == exists
                 and norm_relative_path(f["name"]) == norm_wlock
             ):
                 return True
     return False
예제 #4
0
    def test_reUseNestedWatch(self):
        d = self.mkdtemp()
        abc = os.path.join(d, "a", "b", "c")
        os.makedirs(abc, 0o777)
        self.touchRelative(abc, ".watchmanconfig")

        res = self.watchmanCommand("watch-project", d)
        self.assertEqual(d, norm_absolute_path(res["watch"]))

        res = self.watchmanCommand("watch-project", abc)
        self.assertEqual(d, norm_absolute_path(res["watch"]))
        self.assertEqual("a/b/c", norm_relative_path(res["relative_path"]))
예제 #5
0
 def findSubscriptionContainingFile(self, subdata, filename):
     filename = norm_relative_path(filename)
     for dat in subdata:
         if "files" in dat and filename in self.normFileList(dat["files"]):
             return dat
     return None
예제 #6
0
 def norm_sub_item(item):
     if isinstance(item, STRING_TYPES):
         return norm_relative_path(item)
     item["name"] = norm_relative_path(item["name"])
     return item
예제 #7
0
 def fileListContains(self, list1, list2):
     """ return true if list1 contains each unique element in list2 """
     set1 = set([norm_relative_path(f) for f in list1])
     list2 = [norm_relative_path(f) for f in list2]
     return set1.issuperset(list2)
예제 #8
0
 def fileListsEqual(self, list1, list2):
     list1 = [norm_relative_path(f) for f in list1]
     list2 = [norm_relative_path(f) for f in list2]
     return sorted(list1) == sorted(list2)
예제 #9
0
 def assertFileListsEqual(self, list1, list2, message=None):
     list1 = [norm_relative_path(f) for f in list1]
     list2 = [norm_relative_path(f) for f in list2]
     self.assertCountEqual(list1, list2, message)
예제 #10
0
 def norm_sub_item(item):
     if isinstance(item, STRING_TYPES):
         return norm_relative_path(item)
     item["name"] = norm_relative_path(item["name"])
     return item
예제 #11
0
 def fileListContains(self, list1, list2):
     """ return true if list1 contains each unique element in list2 """
     set1 = set([norm_relative_path(f) for f in list1])
     list2 = [norm_relative_path(f) for f in list2]
     return set1.issuperset(list2)
예제 #12
0
 def fileListsEqual(self, list1, list2):
     list1 = [norm_relative_path(f) for f in list1]
     list2 = [norm_relative_path(f) for f in list2]
     return sorted(list1) == sorted(list2)
예제 #13
0
 def assertFileListsEqual(self, list1, list2, message=None):
     list1 = [norm_relative_path(f) for f in list1]
     list2 = [norm_relative_path(f) for f in list2]
     self.assertCountEqual(list1, list2, message)
예제 #14
0
 def findSubscriptionContainingFile(self, subdata, filename):
     filename = norm_relative_path(filename)
     for dat in subdata:
         if "files" in dat and filename in self.normFileList(dat["files"]):
             return dat
     return None