@@ -49,7 +49,7 @@ def testSmoke(self):
4949 self .createSimpleFiles ()
5050 exit_code , stdout , stderr = self .RunBazel (['run' , '//a:a' ])
5151 self .AssertExitCode (exit_code , 0 , stderr )
52- self .assertTrue ('Hello, World' in stdout )
52+ self .assertIn ('Hello, World' , stdout )
5353
5454 def testRunfilesSymlinks (self ):
5555 if test_base .TestBase .IsWindows ():
@@ -208,5 +208,115 @@ def testPyTestWithStdlibCollisionRunsRemotely(self):
208208 self .assertIn ('Test ran' , stdout )
209209
210210
211+ class PyRunfilesLibraryTest (test_base .TestBase ):
212+
213+ def testPyRunfilesLibraryCurrentRepository (self ):
214+ self .CreateWorkspaceWithDefaultRepos ('WORKSPACE' , [
215+ 'local_repository(' , ' name = "other_repo",' ,
216+ ' path = "other_repo_path",' , ')'
217+ ])
218+
219+ self .ScratchFile ('pkg/BUILD.bazel' , [
220+ 'py_library(' ,
221+ ' name = "library",' ,
222+ ' srcs = ["library.py"],' ,
223+ ' visibility = ["//visibility:public"],' ,
224+ ' deps = ["@bazel_tools//tools/python/runfiles"],' ,
225+ ')' ,
226+ '' ,
227+ 'py_binary(' ,
228+ ' name = "binary",' ,
229+ ' srcs = ["binary.py"],' ,
230+ ' deps = [' ,
231+ ' ":library",' ,
232+ ' "@bazel_tools//tools/python/runfiles",' ,
233+ ' ],' ,
234+ ')' ,
235+ '' ,
236+ 'py_test(' ,
237+ ' name = "test",' ,
238+ ' srcs = ["test.py"],' ,
239+ ' deps = [' ,
240+ ' ":library",' ,
241+ ' "@bazel_tools//tools/python/runfiles",' ,
242+ ' ],' ,
243+ ')' ,
244+ ])
245+ self .ScratchFile ('pkg/library.py' , [
246+ 'from bazel_tools.tools.python.runfiles import runfiles' ,
247+ 'def print_repo_name():' ,
248+ ' print("in pkg/library.py: \' %s\' " % runfiles.Create().CurrentRepository())' ,
249+ ])
250+ self .ScratchFile ('pkg/binary.py' , [
251+ 'from bazel_tools.tools.python.runfiles import runfiles' ,
252+ 'from pkg import library' ,
253+ 'library.print_repo_name()' ,
254+ 'print("in pkg/binary.py: \' %s\' " % runfiles.Create().CurrentRepository())' ,
255+ ])
256+ self .ScratchFile ('pkg/test.py' , [
257+ 'from bazel_tools.tools.python.runfiles import runfiles' ,
258+ 'from pkg import library' ,
259+ 'library.print_repo_name()' ,
260+ 'print("in pkg/test.py: \' %s\' " % runfiles.Create().CurrentRepository())' ,
261+ ])
262+
263+ self .ScratchFile ('other_repo_path/WORKSPACE' )
264+ self .ScratchFile ('other_repo_path/pkg/BUILD.bazel' , [
265+ 'py_binary(' ,
266+ ' name = "binary",' ,
267+ ' srcs = ["binary.py"],' ,
268+ ' deps = [' ,
269+ ' "@//pkg:library",' ,
270+ ' "@bazel_tools//tools/python/runfiles",' ,
271+ ' ],' ,
272+ ')' ,
273+ '' ,
274+ 'py_test(' ,
275+ ' name = "test",' ,
276+ ' srcs = ["test.py"],' ,
277+ ' deps = [' ,
278+ ' "@//pkg:library",' ,
279+ ' "@bazel_tools//tools/python/runfiles",' ,
280+ ' ],' ,
281+ ')' ,
282+ ])
283+ self .ScratchFile ('other_repo_path/pkg/binary.py' , [
284+ 'from bazel_tools.tools.python.runfiles import runfiles' ,
285+ 'from pkg import library' ,
286+ 'library.print_repo_name()' ,
287+ 'print("in external/other_repo/pkg/binary.py: \' %s\' " % runfiles.Create().CurrentRepository())' ,
288+ ])
289+ self .ScratchFile ('other_repo_path/pkg/test.py' , [
290+ 'from bazel_tools.tools.python.runfiles import runfiles' ,
291+ 'from pkg import library' ,
292+ 'library.print_repo_name()' ,
293+ 'print("in external/other_repo/pkg/test.py: \' %s\' " % runfiles.Create().CurrentRepository())' ,
294+ ])
295+
296+ exit_code , stdout , stderr = self .RunBazel (['run' , '//pkg:binary' ])
297+ self .AssertExitCode (exit_code , 0 , stderr , stdout )
298+ self .assertIn ('in pkg/binary.py: \' \' ' , stdout )
299+ self .assertIn ('in pkg/library.py: \' \' ' , stdout )
300+
301+ exit_code , stdout , stderr = self .RunBazel (
302+ ['test' , '//pkg:test' , '--test_output=streamed' ])
303+ self .AssertExitCode (exit_code , 0 , stderr , stdout )
304+ self .assertIn ('in pkg/test.py: \' \' ' , stdout )
305+ self .assertIn ('in pkg/library.py: \' \' ' , stdout )
306+
307+ exit_code , stdout , stderr = self .RunBazel (
308+ ['run' , '@other_repo//pkg:binary' ])
309+ self .AssertExitCode (exit_code , 0 , stderr , stdout )
310+ self .assertIn ('in external/other_repo/pkg/binary.py: \' other_repo\' ' ,
311+ stdout )
312+ self .assertIn ('in pkg/library.py: \' \' ' , stdout )
313+
314+ exit_code , stdout , stderr = self .RunBazel (
315+ ['test' , '@other_repo//pkg:test' , '--test_output=streamed' ])
316+ self .AssertExitCode (exit_code , 0 , stderr , stdout )
317+ self .assertIn ('in external/other_repo/pkg/test.py: \' other_repo\' ' , stdout )
318+ self .assertIn ('in pkg/library.py: \' \' ' , stdout )
319+
320+
211321if __name__ == '__main__' :
212322 unittest .main ()
0 commit comments