aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/py
diff options
context:
space:
mode:
authorGravatar lberki <lberki@google.com>2018-02-15 01:18:23 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-15 01:20:11 -0800
commite9c885a88137fa10ea0ac95ff33dcfdc79c6cf0a (patch)
treeab659dd61c32440be620319bad64f55cec09320d /src/test/py
parent0a8dde0a64c3eea0a5b93560cdacc66db4a6885c (diff)
Automated rollback of commit fa0fac2a4e8a2e5c01b8390878289d00dcc17dba.
*** Reason for rollback *** Remove example changes; those need to build with the last Bazel release. *** Original change description *** Automated rollback of commit 0f9c6ea574918dda094cf5423fa3822112846c30. *** Reason for rollback *** Breaks Kokoro and I accidentally submitted the change without presubmit checks. *** Original change description *** Make __init__.py files creation optional Introduce a new attribute to py_binary and py_test to control whether to create `__init__.py` or not. Fixes https://github.com/bazelbuild/rules_python/issues/55 Closes #4470. PiperOrigin-RevId: 185806241
Diffstat (limited to 'src/test/py')
-rw-r--r--src/test/py/bazel/py_test.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/py/bazel/py_test.py b/src/test/py/bazel/py_test.py
index 26fe88a0d6..3d97e79105 100644
--- a/src/test/py/bazel/py_test.py
+++ b/src/test/py/bazel/py_test.py
@@ -65,5 +65,46 @@ class PyTest(test_base.TestBase):
.endswith('/a/b.py'))
+class TestInitPyFiles(test_base.TestBase):
+
+ def createSimpleFiles(self, create_init=True):
+ self.ScratchFile('WORKSPACE')
+
+ self.ScratchFile('src/a/BUILD', [
+ 'py_binary(name="a", srcs=["a.py"], deps=[":b"], legacy_create_init=%s)'
+ % create_init,
+ 'py_library(name="b", srcs=["b.py"])',
+ ])
+
+ self.ScratchFile('src/a/a.py', [
+ 'from src.a import b',
+ 'b.Hello()',
+ ])
+
+ self.ScratchFile('src/a/b.py', [
+ 'def Hello():',
+ ' print("Hello, World")',
+ ])
+
+ def testInitPyFilesCreated(self):
+ self.createSimpleFiles()
+ exit_code, _, stderr = self.RunBazel(['build', '//src/a:a'])
+ self.AssertExitCode(exit_code, 0, stderr)
+ self.assertTrue(
+ os.path.exists('bazel-bin/src/a/a.runfiles/__main__/src/__init__.py'))
+ self.assertTrue(
+ os.path.exists('bazel-bin/src/a/a.runfiles/__main__/src/a/__init__.py'))
+
+
+def testInitPyFilesNotCreatedWhenLegacyCreateInitIsSet(self):
+ self.createSimpleFiles(create_init=False)
+ exit_code, _, stderr = self.RunBazel(['build', '//src/a:a'])
+ self.AssertExitCode(exit_code, 0, stderr)
+ self.assertFalse(
+ os.path.exists('bazel-bin/src/a/a.runfiles/__main__/src/__init__.py'))
+ self.assertFalse(
+ os.path.exists('bazel-bin/src/a/a.runfiles/__main__/src/a/__init__.py'))
+
+
if __name__ == '__main__':
unittest.main()