aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/py
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-02-23 08:17:09 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-23 08:19:16 -0800
commit27043ed144d8442098361faa4a70611788f7eaa3 (patch)
tree0467aa049a0efdf15c779657732c9ae7aa6ee273 /src/test/py
parentc4b49f276fc4a410f8f249e32f30ac4602724a95 (diff)
windows,tests: fix //src/test/py/bazel:py_test
The test was failing because it assumed Bazel was generating a runfiles tree for py_binary. On Windows, Bazel actually builds a zip file which contains the py_binary's runfiles tree. This commit adjusts the tests to assert the zip file's contents when the test is running on Windows. Fixes https://github.com/bazelbuild/bazel/issues/4673 Change-Id: I7544bff6c1866249b8e7982b1a106202d78e10d9 PiperOrigin-RevId: 186770549
Diffstat (limited to 'src/test/py')
-rw-r--r--src/test/py/bazel/py_test.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/test/py/bazel/py_test.py b/src/test/py/bazel/py_test.py
index 3d97e79105..d2269ad391 100644
--- a/src/test/py/bazel/py_test.py
+++ b/src/test/py/bazel/py_test.py
@@ -14,6 +14,7 @@
import os
import unittest
+import zipfile
from src.test.py.bazel import test_base
@@ -90,21 +91,29 @@ class TestInitPyFiles(test_base.TestBase):
self.createSimpleFiles()
exit_code, _, stderr = self.RunBazel(['build', '//src/a:a'])
self.AssertExitCode(exit_code, 0, stderr)
- self.assertTrue(
+ if self.IsWindows():
+ # On Windows Bazel creates bazel-bin/src/a/a.zip
+ self.assertTrue(os.path.exists('bazel-bin/src/a/a.zip'))
+ with zipfile.ZipFile('bazel-bin/src/a/a.zip', 'r') as z:
+ zip_contents = set(z.namelist())
+ self.assertIn('runfiles/__main__/src/__init__.py', zip_contents)
+ self.assertIn('runfiles/__main__/src/a/__init__.py', zip_contents)
+ else:
+ 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.assertTrue(
+ self.assertFalse(
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()