Example #1
0
 def testFailsToCreateAnyRunfilesBecauseEnvvarsAreNotDefined(self):
     with _MockFile(contents=["a b"]) as mf:
         runfiles.Create({
             "RUNFILES_MANIFEST_FILE": mf.Path(),
             "RUNFILES_DIR": "whatever",
             "TEST_SRCDIR": "always ignored",
         })
     runfiles.Create({
         "RUNFILES_DIR": "whatever",
         "TEST_SRCDIR": "always ignored",
     })
     self.assertIsNone(runfiles.Create({"TEST_SRCDIR": "always ignored"}))
     self.assertIsNone(runfiles.Create({"FOO": "bar"}))
Example #2
0
 def testRlocationArgumentValidation(self):
     r = runfiles.Create({"RUNFILES_DIR": "whatever"})
     self.assertRaises(ValueError, lambda: r.Rlocation(None))
     self.assertRaises(ValueError, lambda: r.Rlocation(""))
     self.assertRaises(TypeError, lambda: r.Rlocation(1))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("../foo"))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("foo/.."))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("foo/../bar"))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("./foo"))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("foo/."))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("foo/./bar"))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("//foobar"))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("foo//"))
     self.assertRaisesRegexp(ValueError, "is not normalized",
                             lambda: r.Rlocation("foo//bar"))
     self.assertRaisesRegexp(ValueError,
                             "is absolute without a drive letter",
                             lambda: r.Rlocation("\\foo"))
Example #3
0
 def testCreatesDirectoryBasedRunfiles(self):
     r = runfiles.Create({
         "RUNFILES_DIR": "runfiles/dir",
         "TEST_SRCDIR": "always ignored",
     })
     self.assertEqual(r.Rlocation("a/b"), "runfiles/dir/a/b")
     self.assertEqual(r.Rlocation("foo"), "runfiles/dir/foo")
Example #4
0
 def testDirectoryBasedRunfilesEnvVars(self):
     r = runfiles.Create({
         "RUNFILES_DIR": "runfiles/dir",
         "TEST_SRCDIR": "always ignored",
     })
     self.assertDictEqual(r.EnvVars(), {
         "RUNFILES_DIR": "runfiles/dir",
         "JAVA_RUNFILES": "runfiles/dir",
     })
Example #5
0
 def testCreatesManifestBasedRunfiles(self):
   with _MockFile(contents=["a/b c/d"]) as mf:
     r = runfiles.Create({
         "RUNFILES_MANIFEST_FILE": mf.Path(),
         "RUNFILES_DIR": "ignored when RUNFILES_MANIFEST_FILE has a value",
         "TEST_SRCDIR": "always ignored",
     })
     self.assertEqual(r.Rlocation("a/b"), "c/d")
     self.assertIsNone(r.Rlocation("foo"))
Example #6
0
 def testRlocationArgumentValidation(self):
   r = runfiles.Create({"RUNFILES_DIR": "whatever"})
   self.assertRaises(ValueError, lambda: r.Rlocation(None))
   self.assertRaises(ValueError, lambda: r.Rlocation(""))
   self.assertRaises(TypeError, lambda: r.Rlocation(1))
   self.assertRaisesRegexp(ValueError, "contains uplevel",
                           lambda: r.Rlocation("foo/.."))
   self.assertRaisesRegexp(ValueError, "is absolute without a drive letter",
                           lambda: r.Rlocation("\\foo"))
Example #7
0
    def testManifestBasedRunfilesEnvVars(self):
        with _MockFile(name="MANIFEST") as mf:
            r = runfiles.Create({
                "RUNFILES_MANIFEST_FILE": mf.Path(),
                "TEST_SRCDIR": "always ignored",
            })
            self.assertDictEqual(
                r.EnvVars(), {
                    "RUNFILES_MANIFEST_FILE": mf.Path(),
                    "RUNFILES_DIR": mf.Path()[:-len("/MANIFEST")],
                    "JAVA_RUNFILES": mf.Path()[:-len("/MANIFEST")],
                })

        with _MockFile(name="foo.runfiles_manifest") as mf:
            r = runfiles.Create({
                "RUNFILES_MANIFEST_FILE": mf.Path(),
                "TEST_SRCDIR": "always ignored",
            })
            self.assertDictEqual(
                r.EnvVars(), {
                    "RUNFILES_MANIFEST_FILE":
                    mf.Path(),
                    "RUNFILES_DIR":
                    (mf.Path()[:-len("foo.runfiles_manifest")] +
                     "foo.runfiles"),
                    "JAVA_RUNFILES":
                    (mf.Path()[:-len("foo.runfiles_manifest")] +
                     "foo.runfiles"),
                })

        with _MockFile(name="x_manifest") as mf:
            r = runfiles.Create({
                "RUNFILES_MANIFEST_FILE": mf.Path(),
                "TEST_SRCDIR": "always ignored",
            })
            self.assertDictEqual(
                r.EnvVars(), {
                    "RUNFILES_MANIFEST_FILE": mf.Path(),
                    "RUNFILES_DIR": "",
                    "JAVA_RUNFILES": "",
                })
Example #8
0
 def _Run():
     runfiles.Create({"RUNFILES_MANIFEST_FILE": "non-existing path"})