From 32fa3ff86546893711558d5d8539d4b2d960796a Mon Sep 17 00:00:00 2001 From: Chris Cummins Date: Fri, 2 Apr 2021 00:21:37 +0100 Subject: [PATCH] [tests] Add a test of compiler gym version number. --- tests/BUILD | 2 ++ tests/pytest_plugins/common.py | 5 +++++ tests/version_test.py | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/tests/BUILD b/tests/BUILD index 954c14e88..563ce1c78 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -97,8 +97,10 @@ py_test( name = "version_test", timeout = "short", srcs = ["version_test.py"], + data = ["//:VERSION"], deps = [ ":test_main", "//compiler_gym", + "//tests/pytest_plugins:common", ], ) diff --git a/tests/pytest_plugins/common.py b/tests/pytest_plugins/common.py index 3e5c77ee2..44266de08 100644 --- a/tests/pytest_plugins/common.py +++ b/tests/pytest_plugins/common.py @@ -23,6 +23,11 @@ not sys.platform.lower().startswith("darwin"), reason="macOS only" ) +# Decorator to mark a test as skipped if not running under bazel. +bazel_only = pytest.mark.skipif( + os.environ.get("TEST_WORKSPACE", "") == "", reason="bazel only" +) + @pytest.fixture(scope="function") def tmpwd() -> Path: diff --git a/tests/version_test.py b/tests/version_test.py index 7dc486eb2..b5af4aa48 100644 --- a/tests/version_test.py +++ b/tests/version_test.py @@ -8,7 +8,9 @@ import pytest import compiler_gym +from compiler_gym.util.runfiles_path import runfiles_path from packaging import version +from tests.pytest_plugins.common import bazel_only from tests.test_main import main # Marker to skip a test if running under bazel. @@ -33,5 +35,13 @@ def test_setuptools_version(): assert version == compiler_gym.__version__ +@bazel_only +def test_expected_version(): + """Test that embedded compiler gym version matches VERSION file.""" + with open(runfiles_path("VERSION")) as f: + version = f.read().strip() + assert version == compiler_gym.__version__ + + if __name__ == "__main__": main()