From 6e4010de0a27a867a1e898c0080d6f98dc1f6b8e Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Mon, 16 Sep 2024 14:57:28 +0100 Subject: [PATCH 1/3] refactor: move executor tests --- labgrid/executor/BUILD.bazel | 42 +-------------------- tests/executor/BUILD.bazel | 40 ++++++++++++++++++++ {labgrid => tests}/executor/hello-world.txt | 0 {labgrid => tests}/executor/host.py | 4 +- 4 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 tests/executor/BUILD.bazel rename {labgrid => tests}/executor/hello-world.txt (100%) rename {labgrid => tests}/executor/host.py (72%) diff --git a/labgrid/executor/BUILD.bazel b/labgrid/executor/BUILD.bazel index ba75acaf..0768a12c 100644 --- a/labgrid/executor/BUILD.bazel +++ b/labgrid/executor/BUILD.bazel @@ -1,5 +1,4 @@ -load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") -load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target") +load("@rules_python//python:defs.bzl", "py_binary") exports_files( ["executor.py"], @@ -23,42 +22,3 @@ py_binary( visibility = ["//visibility:public"], deps = ["//bazel/labgrid/executor"], ) - -py_library( - name = "host", - srcs = ["host.py"], - data = ["hello-world.txt"], - deps = [ - "//bazel/labgrid/executor", - "@rules_python//python/runfiles", - ], -) - -py_test( - name = "argument", - size = "small", - srcs = [":srcs"], - args = [ - "--manager", - "labgrid.executor.host:manager", - "echo", - "$${DATA}", - ], - main = ":main", - deps = ["host"], -) - -py_test( - name = "envvar", - size = "small", - srcs = [":srcs"], - args = [ - "echo", - "$${DATA}", - ], - env = { - "LABGRID_EXECUTOR_MANAGER": "labgrid.executor.host:manager", - }, - main = ":main", - deps = ["host"], -) diff --git a/tests/executor/BUILD.bazel b/tests/executor/BUILD.bazel new file mode 100644 index 00000000..f0880f17 --- /dev/null +++ b/tests/executor/BUILD.bazel @@ -0,0 +1,40 @@ +load("@rules_python//python:defs.bzl", "py_library", "py_test") + +py_library( + name = "host", + srcs = ["host.py"], + data = ["hello-world.txt"], + deps = [ + "//bazel/labgrid/executor", + "@rules_python//python/runfiles", + ], +) + +py_test( + name = "argument", + size = "small", + srcs = ["//labgrid/executor:srcs"], + args = [ + "--manager", + "tests.executor.host:manager", + "echo", + "$${DATA}", + ], + main = "//labgrid/executor:main", + deps = ["host"], +) + +py_test( + name = "envvar", + size = "small", + srcs = ["//labgrid/executor:srcs"], + args = [ + "echo", + "$${DATA}", + ], + env = { + "LABGRID_EXECUTOR_MANAGER": "tests.executor.host:manager", + }, + main = "//labgrid/executor:main", + deps = ["host"], +) diff --git a/labgrid/executor/hello-world.txt b/tests/executor/hello-world.txt similarity index 100% rename from labgrid/executor/hello-world.txt rename to tests/executor/hello-world.txt diff --git a/labgrid/executor/host.py b/tests/executor/host.py similarity index 72% rename from labgrid/executor/host.py rename to tests/executor/host.py index d638d9e4..27b771cb 100644 --- a/labgrid/executor/host.py +++ b/tests/executor/host.py @@ -5,13 +5,13 @@ from typing import Iterator from python.runfiles import Runfiles -from bazel.labgrid.executor.manager import Data, Manager +from bazel.labgrid.executor.manager import Data @contextmanager def manager() -> Iterator[Run]: runfiles = Runfiles.Create() - path = runfiles.Rlocation("_main/labgrid/executor/hello-world.txt") + path = runfiles.Rlocation("_main/tests/executor/hello-world.txt") with open(path) as stream: data = stream.read() env = {"DATA": data} -- GitLab From 837a55c81710bf5b2dab74ce1141b04fc83f9df7 Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Mon, 16 Sep 2024 16:57:08 +0100 Subject: [PATCH 2/3] refactor: move qemu-system tests --- labgrid/toolchain/qemu-system/BUILD.bazel | 8 -------- tests/toolchain/qemu-system/BUILD.bazel | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 tests/toolchain/qemu-system/BUILD.bazel diff --git a/labgrid/toolchain/qemu-system/BUILD.bazel b/labgrid/toolchain/qemu-system/BUILD.bazel index 354522b9..8a91fbf9 100644 --- a/labgrid/toolchain/qemu-system/BUILD.bazel +++ b/labgrid/toolchain/qemu-system/BUILD.bazel @@ -1,5 +1,4 @@ load("@toolchain_utils//toolchain/info:defs.bzl", "toolchain_info") -load("@toolchain_utils//toolchain/test:defs.bzl", "toolchain_test") toolchain_type( name = "type", @@ -39,10 +38,3 @@ alias( actual = "@resolved-qemu-system", visibility = ["//visibility:public"], ) - -toolchain_test( - name = "test", - size = "small", - args = ["--version"], - toolchains = [":resolved"], -) diff --git a/tests/toolchain/qemu-system/BUILD.bazel b/tests/toolchain/qemu-system/BUILD.bazel new file mode 100644 index 00000000..a8b934d3 --- /dev/null +++ b/tests/toolchain/qemu-system/BUILD.bazel @@ -0,0 +1,8 @@ +load("@toolchain_utils//toolchain/test:defs.bzl", "toolchain_test") + +toolchain_test( + name = "resolved", + size = "small", + args = ["--version"], + toolchains = ["//labgrid/toolchain/qemu-system:resolved"], +) -- GitLab From d583b06303910118dbe3a744d11e7a506f3b8199 Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Mon, 16 Sep 2024 16:59:10 +0100 Subject: [PATCH 3/3] refactor: move python tests --- labgrid/python/BUILD.bazel | 7 ------- tests/python/BUILD.bazel | 8 ++++++++ .../python/test.py => tests/python/test_module_loading.py | 6 ++---- 3 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 tests/python/BUILD.bazel rename labgrid/python/test.py => tests/python/test_module_loading.py (77%) diff --git a/labgrid/python/BUILD.bazel b/labgrid/python/BUILD.bazel index 3e4a1a7b..6609c860 100644 --- a/labgrid/python/BUILD.bazel +++ b/labgrid/python/BUILD.bazel @@ -1,4 +1,3 @@ -load("@rules_python//python:defs.bzl", "py_test") load("@python_versions//3.11:defs.bzl", "compile_pip_requirements") # TODO: generate for more Python interpreter versions and platforms @@ -16,9 +15,3 @@ alias( actual = "@rules_labgrid-labgrid-python//labgrid", visibility = ["//visibility:public"], ) - -py_test( - name = "test", - srcs = ["test.py"], - deps = [":python"], -) diff --git a/tests/python/BUILD.bazel b/tests/python/BUILD.bazel new file mode 100644 index 00000000..c6d8f087 --- /dev/null +++ b/tests/python/BUILD.bazel @@ -0,0 +1,8 @@ +load("@rules_python//python:defs.bzl", "py_test") + +py_test( + name = "module-loading", + srcs = ["test_module_loading.py"], + main = "test_module_loading.py", + deps = ["//labgrid/python"], +) diff --git a/labgrid/python/test.py b/tests/python/test_module_loading.py similarity index 77% rename from labgrid/python/test.py rename to tests/python/test_module_loading.py index 1bff2fa9..13314536 100644 --- a/labgrid/python/test.py +++ b/tests/python/test_module_loading.py @@ -1,13 +1,11 @@ from __future__ import annotations from importlib import import_module -from os import environ -from pathlib import Path from unittest import TestCase, main -class ModuleTestCase(TestCase): - def test_load(self): +class ModuleLoadingTestCase(TestCase): + def test_load_labgrid(self): module = import_module("labgrid") name = "rules_labgrid-labgrid-python" # Validate that `labgrid` is loaded from our `pip.parse` hub -- GitLab