From d9aa13959a40a2e1907217d397a9c2252273fc49 Mon Sep 17 00:00:00 2001 From: Millian Poquet <millian.poquet@irit.fr> Date: Sun, 13 Nov 2022 23:04:20 +0100 Subject: [PATCH] unit tests++ --- .gitlab-ci.yml | 11 +++++++++-- client-py/client.py | 3 +++ client-py/test_client.py | 6 ++++++ default.nix | 9 +++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 client-py/test_client.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 984d28d..e8d8cbb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,10 @@ debian: script: # Get various dependencies - apt update -y - - apt install -y g++ libsimgrid-dev libzmq3-dev libprotobuf-dev protobuf-compiler libgtest-dev meson ninja-build pkg-config python3 python3-pip + - apt install -y g++ libsimgrid-dev libzmq3-dev libprotobuf-dev protobuf-compiler libgtest-dev meson ninja-build pkg-config python3 python3-pip python3-pytest + + # Put pip-installed binaries in PATH + - export PATH="${PATH}:/usr/local/bin" # Build protocol (c++) - (cd protocol && meson setup build --prefix=/usr && ninja -C build && meson install -C build) @@ -29,10 +32,13 @@ debian: # Run unit tests (simgrid simulator, c++) - (cd simgrid-simulator && meson test -C build) + # Run unit tests (python) + - (cd client-py && pytest .) + # Run integration tests (simgrid simulator VS c++ client) - test/simulator-cpp-client.sh # Run integration tests (simgrid simulator VS python client) - - PATH="${PATH}:/usr/local/bin" test/simulator-py-client.sh + - test/simulator-py-client.sh artifacts: paths: - client-cpp.err @@ -54,5 +60,6 @@ nix: # Any dependency will also be built, for example the following command also builds protocol-python - nix-build . -A client-py # Therefore one can just run its desired leaf of the build tree, such as: + - nix-shell . -A client-py_unittest_shell --command '(cd client-py && pytest)' - nix-shell . -A integration_shell_cpp --command './test/simulator-cpp-client.sh' - nix-shell . -A integration_shell_py --command './test/simulator-py-client.sh' diff --git a/client-py/client.py b/client-py/client.py index 1b527b4..1adddfa 100755 --- a/client-py/client.py +++ b/client-py/client.py @@ -2,6 +2,9 @@ import zmq import protocol.hello_pb2 as proto +def some_function(x): + return x*2 + def main(): context = zmq.Context() socket = context.socket(zmq.REP) diff --git a/client-py/test_client.py b/client-py/test_client.py new file mode 100644 index 0000000..ba292d5 --- /dev/null +++ b/client-py/test_client.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +import client + +def test_some_function(): + for i in range(10): + assert(client.some_function(i) == i*2) diff --git a/default.nix b/default.nix index 05eab10..d9b4a6b 100644 --- a/default.nix +++ b/default.nix @@ -44,7 +44,11 @@ let self = rec { "src" "src/.*\.cpp" "src/.*\.hpp" + "test" + "test/.*\.cpp" ]; + mesonFlags = [ "-Ddo_unit_tests=true" ]; + doCheck = true; buildInputs = with pkgs; [ simgrid protocol-cpp @@ -85,6 +89,11 @@ let self = rec { ]; }; + client-py_unittest_shell = pkgs.mkShell { + buildInputs = client-py.propagatedBuildInputs ++ [ + pythonPackages.pytest + ]; + }; integration_shell_cpp = pkgs.mkShell { buildInputs = [ simgrid-simulator -- GitLab