aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2015-04-17 15:31:02 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-04-17 15:43:17 +0000
commita8628bfffa72994759e4ac8bb45f317c4f33c05d (patch)
tree8f02a328a4e7d238aa126885808208cad39cfb0f /examples
parent666762c7d1681e16acea75f4eef850b93fe91098 (diff)
Added py_test rule to Bazel
py_test rule enable to use a test written in Python. A py_test is basically a py_binary that returns a non null on failure. Extraneous support is need to have nice output (see //src/test/shell/unittest.bash for the kind of support neeeded). Actually the py_test code was already there but it was just missing the necessary glue code. Also added an integration test for py_* rules in Bazel. -- MOS_MIGRATED_REVID=91407748
Diffstat (limited to 'examples')
-rw-r--r--examples/BUILD1
-rw-r--r--examples/py_native/BUILD18
-rw-r--r--examples/py_native/fail.py13
-rw-r--r--examples/py_native/test.py13
4 files changed, 45 insertions, 0 deletions
diff --git a/examples/BUILD b/examples/BUILD
index 0e42866a36..3ce954ea6a 100644
--- a/examples/BUILD
+++ b/examples/BUILD
@@ -10,5 +10,6 @@ filegroup(
"//examples/objc:srcs",
"//examples/proto:srcs",
"//examples/py:srcs",
+ "//examples/py_native:srcs",
],
)
diff --git a/examples/py_native/BUILD b/examples/py_native/BUILD
index 3d8de94251..d6fdfa957b 100644
--- a/examples/py_native/BUILD
+++ b/examples/py_native/BUILD
@@ -1,3 +1,9 @@
+filegroup(
+ name = "srcs",
+ srcs = glob(["*.py"]) + ["BUILD"],
+ visibility = ["//examples:__pkg__"],
+)
+
py_binary(
name = "bin",
srcs = ["bin.py"],
@@ -8,3 +14,15 @@ py_library(
name = "lib",
srcs = ["lib.py"],
)
+
+py_test(
+ name = "test",
+ srcs = ["test.py"],
+ deps = [":lib"],
+)
+
+py_test(
+ name = "fail",
+ srcs = ["fail.py"],
+ deps = [":lib"],
+)
diff --git a/examples/py_native/fail.py b/examples/py_native/fail.py
new file mode 100644
index 0000000000..98e35f4ee7
--- /dev/null
+++ b/examples/py_native/fail.py
@@ -0,0 +1,13 @@
+"""A tiny example binary for the native Python rules of Bazel."""
+import unittest
+from examples.py_native.lib import GetNumber
+
+
+class TestGetNumber(unittest.TestCase):
+
+ def test_fail(self):
+ self.assertEquals(GetNumber(), 0)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/examples/py_native/test.py b/examples/py_native/test.py
new file mode 100644
index 0000000000..811eee144e
--- /dev/null
+++ b/examples/py_native/test.py
@@ -0,0 +1,13 @@
+"""A tiny example binary for the native Python rules of Bazel."""
+import unittest
+from examples.py_native.lib import GetNumber
+
+
+class TestGetNumber(unittest.TestCase):
+
+ def test_ok(self):
+ self.assertEquals(GetNumber(), 42)
+
+
+if __name__ == '__main__':
+ unittest.main()