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"}))
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"))
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")
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", })
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"))
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"))
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": "", })
def _Run(): runfiles.Create({"RUNFILES_MANIFEST_FILE": "non-existing path"})