aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-06-07 15:06:51 -0400
committerGravatar John Cater <jcater@google.com>2017-06-08 10:52:44 -0400
commit62c3105a159db52779d49f7fbd98099d71a51852 (patch)
tree8b969e46fe6d69e12cc46bb83d5d50a5640656c4 /src/test
parent4ed112830894161614d9b33ee26b0f9f74eb05d9 (diff)
Switch to correct runfiles directory when running python test on Windows
py_test cannot find it's data file at runtime. The reason is it's running in a wrong directory. The test directory is set to runfiles directory by test-setup.sh, but on Windows, python binary unzip itself to another temp directory which test-setup.sh doesn't know. So let the python stub template switch to the correct runfiles directory if RUN_UNDER_RUNFILES = 1 Fixed https://github.com/bazelbuild/bazel/issues/3134 Change-Id: If5dbee811330372d86484ebd871ea55d84bc29a8 PiperOrigin-RevId: 158299041
Diffstat (limited to 'src/test')
-rwxr-xr-xsrc/test/shell/bazel/bazel_windows_example_test.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/shell/bazel/bazel_windows_example_test.sh b/src/test/shell/bazel/bazel_windows_example_test.sh
index c62963561c..c8fb2bef07 100755
--- a/src/test/shell/bazel/bazel_windows_example_test.sh
+++ b/src/test/shell/bazel/bazel_windows_example_test.sh
@@ -167,5 +167,51 @@ function test_native_python_with_python3() {
fi
}
+function test_python_test_with_data() {
+ touch BUILD
+ touch WORKSPACE
+
+ mkdir data
+ cat >data/BUILD <<EOF
+filegroup(
+ name = "test_data",
+ srcs = ["data.txt"],
+ visibility = ["//visibility:public"],
+)
+EOF
+
+ cat >data/data.txt <<EOF
+hello world
+EOF
+
+ mkdir src
+ cat >src/BUILD <<EOF
+py_test(
+ name = "data_test",
+ srcs = ["data_test.py"],
+ data = ["//data:test_data"],
+)
+EOF
+
+ cat >src/data_test.py <<EOF
+import unittest
+import os
+
+class MyTest(unittest.TestCase):
+
+ def test_data(self):
+ with open("data/data.txt") as f:
+ line = f.readline().strip()
+ self.assertEqual(line, "hello world")
+
+if __name__ == '__main__':
+ print("CWD = " + os.getcwd())
+ unittest.main()
+EOF
+
+ bazel test --test_output=errors //src:data_test >& $TEST_log \
+ || fail "Test //src:test failed while expecting success"
+}
+
run_suite "examples on Windows"