From f5abb37a55c6bbbdff47a9db6b0cabd5ecabd583 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 06:59:01 +0000 Subject: [PATCH] refactor(test): migrate repo_utils tests to shared mocks Previously, a duplicate and less complete mock implementation existed at `tests/support/mocks.bzl`, while a more comprehensive one was available at `tests/support/mocks/mocks.bzl`. This duplication could lead to confusion and inconsistency in testing. To resolve this, we have removed the redundant `tests/support/mocks.bzl` file and updated the `repo_utils` tests to use the shared mocks from `//tests/support/mocks:mocks.bzl`. --- tests/repo_utils/repo_utils_test.bzl | 2 +- tests/support/mocks.bzl | 31 ---------------------------- 2 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 tests/support/mocks.bzl diff --git a/tests/repo_utils/repo_utils_test.bzl b/tests/repo_utils/repo_utils_test.bzl index ce9e48b5a6..84ccc00528 100644 --- a/tests/repo_utils/repo_utils_test.bzl +++ b/tests/repo_utils/repo_utils_test.bzl @@ -2,7 +2,7 @@ load("@rules_testing//lib:test_suite.bzl", "test_suite") load("//python/private:repo_utils.bzl", "repo_utils") # buildifier: disable=bzl-visibility -load("//tests/support:mocks.bzl", "mocks") +load("//tests/support/mocks:mocks.bzl", "mocks") _tests = [] diff --git a/tests/support/mocks.bzl b/tests/support/mocks.bzl deleted file mode 100644 index 2a4ccd0fc4..0000000000 --- a/tests/support/mocks.bzl +++ /dev/null @@ -1,31 +0,0 @@ -"""Mocks for testing.""" - -def _rctx(os_name = "linux", os_arch = "x86_64", environ = None, **kwargs): - """Creates a mock of repository_ctx or module_ctx. - - Args: - os_name: The OS name to mock (e.g., "linux", "Mac OS X", "windows"). - os_arch: The OS architecture to mock (e.g., "x86_64", "aarch64"). - environ: A dictionary representing the environment variables. - **kwargs: Additional attributes to add to the mock struct. - - Returns: - A struct mocking repository_ctx. - """ - if environ == None: - environ = {} - - attrs = { - "getenv": environ.get, - "os": struct( - name = os_name, - arch = os_arch, - ), - } - attrs.update(kwargs) - - return struct(**attrs) - -mocks = struct( - rctx = _rctx, -)