support/testing: add python-click tests
authorRicardo Martincoski <ricardo.martincoski@gmail.com>
Fri, 16 Nov 2018 03:57:26 +0000 (01:57 -0200)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Fri, 23 Nov 2018 21:05:46 +0000 (22:05 +0100)
Use a simple script to check the basic usage. Since this package
provides command line arguments, override run_sample_scripts to call the
script with arguments and check the expected output.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
.gitlab-ci.yml
support/testing/tests/package/sample_python_click.py [new file with mode: 0644]
support/testing/tests/package/test_python_click.py [new file with mode: 0644]

index d6f2e6595f6aa5b7f14cac40f0405f07e1e8cba1..eb6a1876158a130943e4184bec32873640ead34e 100644 (file)
@@ -328,6 +328,8 @@ tests.package.test_python_bitstring.TestPythonPy2Bitstring: *runtime_test
 tests.package.test_python_bitstring.TestPythonPy3Bitstring: *runtime_test
 tests.package.test_python_cbor.TestPythonPy2Cbor: *runtime_test
 tests.package.test_python_cbor.TestPythonPy3Cbor: *runtime_test
+tests.package.test_python_click.TestPythonPy2Click: *runtime_test
+tests.package.test_python_click.TestPythonPy3Click: *runtime_test
 tests.package.test_python_crossbar.TestPythonPy3Crossbar: *runtime_test
 tests.package.test_python_cryptography.TestPythonPy2Cryptography: *runtime_test
 tests.package.test_python_cryptography.TestPythonPy3Cryptography: *runtime_test
diff --git a/support/testing/tests/package/sample_python_click.py b/support/testing/tests/package/sample_python_click.py
new file mode 100644 (file)
index 0000000..759868d
--- /dev/null
@@ -0,0 +1,12 @@
+import click
+
+
+@click.command()
+@click.argument("foo")
+@click.option("--bar", is_flag=True, help="help for bar")
+def main(foo, bar):
+    click.echo("{}, {}".format(foo, bar))
+
+
+if __name__ == '__main__':
+    main()
diff --git a/support/testing/tests/package/test_python_click.py b/support/testing/tests/package/test_python_click.py
new file mode 100644 (file)
index 0000000..db57d3a
--- /dev/null
@@ -0,0 +1,44 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonClick(TestPythonPackageBase):
+    sample_scripts = ["tests/package/sample_python_click.py"]
+
+    def run_sample_scripts(self):
+        cmd = self.interpreter + " sample_python_click.py --help"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertIn("Usage:", output[0])
+        self.assertEqual(exit_code, 0)
+
+        cmd = self.interpreter + " sample_python_click.py 123"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(output[0], "123, False")
+        self.assertEqual(exit_code, 0)
+
+        cmd = self.interpreter + " sample_python_click.py --bar 456"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(output[0], "456, True")
+        self.assertEqual(exit_code, 0)
+
+        cmd = self.interpreter + " sample_python_click.py"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertIn("Usage:", output[0])
+        self.assertEqual(exit_code, 2)
+
+
+class TestPythonPy2Click(TestPythonClick):
+    __test__ = True
+    config = TestPythonClick.config + \
+        """
+        BR2_PACKAGE_PYTHON=y
+        BR2_PACKAGE_PYTHON_CLICK=y
+        """
+
+
+class TestPythonPy3Click(TestPythonClick):
+    __test__ = True
+    config = TestPythonClick.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_CLICK=y
+        """