diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e1c50cd3b96..521e3f9b60c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,7 +47,8 @@ repos: packages/syft/src/syft/proto.*| packages/syft/tests/syft/lib/python.*| packages/grid.*| - packages/syft/src/syft/federated/model_serialization/protos.py + packages/syft/src/syft/federated/model_serialization/protos.py| + packages/syft/src/syft/util/test_helpers/.*| )$ - repo: https://github.com/MarcoGorelli/absolufy-imports @@ -161,6 +162,7 @@ repos: "--non-interactive", "--config-file=tox.ini", ] + exclude: ^(packages/syft/src/syft/util/test_helpers) - repo: https://github.com/kynan/nbstripout rev: 0.7.1 diff --git a/notebooks/scenarios/bigquery/000-start-and-configure-server-and-admins.ipynb b/notebooks/scenarios/bigquery/000-start-and-configure-server-and-admins.ipynb index 8035f5e61e1..86cbdc836c6 100644 --- a/notebooks/scenarios/bigquery/000-start-and-configure-server-and-admins.ipynb +++ b/notebooks/scenarios/bigquery/000-start-and-configure-server-and-admins.ipynb @@ -20,24 +20,12 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "from os import environ as env\n", "\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", - "\n", - "# third party\n", - "from email_helpers import get_email_server\n", - "# isort: on" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Launch & login" + "from syft.util.test_helpers.email_helpers import get_email_server" ] }, { @@ -249,7 +237,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb b/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb index be9579059eb..a8299b5cdcd 100644 --- a/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb +++ b/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb @@ -20,18 +20,13 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "import os\n", "\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", - "\n", - "# third party\n", - "from email_helpers import Timeout\n", - "from email_helpers import get_email_server\n", - "# isort: on" + "from syft.util.test_helpers.email_helpers import Timeout\n", + "from syft.util.test_helpers.email_helpers import get_email_server" ] }, { @@ -40,14 +35,6 @@ "id": "2", "metadata": {}, "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], "source": [ "environment = os.environ.get(\"ORCHESTRA_DEPLOYMENT_TYPE\", \"python\")\n", "\n", @@ -60,7 +47,7 @@ }, { "cell_type": "markdown", - "id": "4", + "id": "3", "metadata": {}, "source": [ "### Launch server & login" @@ -69,7 +56,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5", + "id": "4", "metadata": {}, "outputs": [], "source": [ @@ -86,7 +73,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -96,7 +83,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -108,7 +95,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8", + "id": "7", "metadata": {}, "outputs": [], "source": [ @@ -118,7 +105,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -128,7 +115,7 @@ }, { "cell_type": "markdown", - "id": "10", + "id": "9", "metadata": {}, "source": [ "### Scale Worker pool" @@ -136,7 +123,7 @@ }, { "cell_type": "markdown", - "id": "11", + "id": "10", "metadata": {}, "source": [ "##### Scale up" @@ -145,7 +132,7 @@ { "cell_type": "code", "execution_count": null, - "id": "12", + "id": "11", "metadata": {}, "outputs": [], "source": [ @@ -159,7 +146,7 @@ { "cell_type": "code", "execution_count": null, - "id": "13", + "id": "12", "metadata": {}, "outputs": [], "source": [ @@ -169,7 +156,7 @@ { "cell_type": "code", "execution_count": null, - "id": "14", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -189,7 +176,7 @@ }, { "cell_type": "markdown", - "id": "15", + "id": "14", "metadata": {}, "source": [ "##### Scale down" @@ -198,7 +185,7 @@ { "cell_type": "code", "execution_count": null, - "id": "16", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -213,7 +200,7 @@ { "cell_type": "code", "execution_count": null, - "id": "17", + "id": "16", "metadata": {}, "outputs": [], "source": [ @@ -232,7 +219,7 @@ { "cell_type": "code", "execution_count": null, - "id": "18", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -245,7 +232,7 @@ }, { "cell_type": "markdown", - "id": "19", + "id": "18", "metadata": {}, "source": [ "#### Delete Worker Pool" @@ -254,7 +241,7 @@ { "cell_type": "code", "execution_count": null, - "id": "20", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -267,7 +254,7 @@ { "cell_type": "code", "execution_count": null, - "id": "21", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -277,7 +264,7 @@ }, { "cell_type": "markdown", - "id": "22", + "id": "21", "metadata": {}, "source": [ "#### Re-launch the default worker pool" @@ -286,7 +273,7 @@ { "cell_type": "code", "execution_count": null, - "id": "23", + "id": "22", "metadata": {}, "outputs": [], "source": [ @@ -296,7 +283,7 @@ { "cell_type": "code", "execution_count": null, - "id": "24", + "id": "23", "metadata": {}, "outputs": [], "source": [ @@ -310,7 +297,7 @@ { "cell_type": "code", "execution_count": null, - "id": "25", + "id": "24", "metadata": {}, "outputs": [], "source": [ @@ -324,7 +311,7 @@ { "cell_type": "code", "execution_count": null, - "id": "26", + "id": "25", "metadata": {}, "outputs": [], "source": [ @@ -334,7 +321,7 @@ { "cell_type": "code", "execution_count": null, - "id": "27", + "id": "26", "metadata": {}, "outputs": [], "source": [ @@ -344,7 +331,7 @@ { "cell_type": "code", "execution_count": null, - "id": "28", + "id": "27", "metadata": {}, "outputs": [], "source": [] diff --git a/notebooks/scenarios/bigquery/010-setup-bigquery-pool.ipynb b/notebooks/scenarios/bigquery/010-setup-bigquery-pool.ipynb index 22f6dfaa977..d72a82f9eb1 100644 --- a/notebooks/scenarios/bigquery/010-setup-bigquery-pool.ipynb +++ b/notebooks/scenarios/bigquery/010-setup-bigquery-pool.ipynb @@ -18,18 +18,13 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "import os\n", "\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", "from syft import test_settings\n", - "\n", - "# third party\n", - "from email_helpers import get_email_server\n", - "# isort: on" + "from syft.util.test_helpers.email_helpers import get_email_server" ] }, { @@ -526,6 +521,11 @@ } ], "metadata": { + "kernelspec": { + "display_name": "syft", + "language": "python", + "name": "python3" + }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -536,7 +536,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.5" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb index b87fd2a7731..9a8bfdcdf9c 100644 --- a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb +++ b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb @@ -22,21 +22,16 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "import os\n", "\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", - "\n", - "# third party\n", - "from email_helpers import SENDER\n", - "from email_helpers import create_user\n", - "from email_helpers import get_email_server\n", - "from email_helpers import make_user\n", - "from email_helpers import save_users\n", - "# isort: on" + "from syft.util.test_helpers.email_helpers import SENDER\n", + "from syft.util.test_helpers.email_helpers import create_user\n", + "from syft.util.test_helpers.email_helpers import get_email_server\n", + "from syft.util.test_helpers.email_helpers import make_user\n", + "from syft.util.test_helpers.email_helpers import save_users" ] }, { diff --git a/notebooks/scenarios/bigquery/020-configure-api.ipynb b/notebooks/scenarios/bigquery/020-configure-api.ipynb index 83abef20ff7..1371dfaf5c7 100644 --- a/notebooks/scenarios/bigquery/020-configure-api.ipynb +++ b/notebooks/scenarios/bigquery/020-configure-api.ipynb @@ -28,22 +28,17 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", "from syft import test_settings\n", - "\n", - "# third party\n", - "from apis import make_schema\n", - "from apis import make_submit_query\n", - "from apis import make_test_query\n", + "from syft.util.test_helpers.apis import make_schema\n", + "from syft.util.test_helpers.apis import make_submit_query\n", + "from syft.util.test_helpers.apis import make_test_query\n", "\n", "# run email server\n", - "from email_helpers import get_email_server\n", - "# isort: on" + "from syft.util.test_helpers.email_helpers import get_email_server" ] }, { diff --git a/notebooks/scenarios/bigquery/021-create-jobs.ipynb b/notebooks/scenarios/bigquery/021-create-jobs.ipynb index 5a14895133a..392103a751c 100644 --- a/notebooks/scenarios/bigquery/021-create-jobs.ipynb +++ b/notebooks/scenarios/bigquery/021-create-jobs.ipynb @@ -33,19 +33,14 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "from collections import Counter\n", "import os\n", "\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", "from syft.service.job.job_stash import JobStatus\n", - "\n", - "# third party\n", - "from email_helpers import get_email_server\n", - "# isort: on" + "from syft.util.test_helpers.email_helpers import get_email_server" ] }, { @@ -125,8 +120,8 @@ "metadata": {}, "outputs": [], "source": [ - "# third party\n", - "from email_helpers import load_users" + "# syft absolute\n", + "from syft.util.test_helpers.email_helpers import load_users" ] }, { @@ -154,10 +149,10 @@ "metadata": {}, "outputs": [], "source": [ - "# third party\n", - "from job_helpers import TestJob\n", - "from job_helpers import create_jobs\n", - "from job_helpers import extract_code_path" + "# syft absolute\n", + "from syft.util.test_helpers.job_helpers import TestJob\n", + "from syft.util.test_helpers.job_helpers import create_jobs\n", + "from syft.util.test_helpers.job_helpers import extract_code_path" ] }, { @@ -199,8 +194,8 @@ "metadata": {}, "outputs": [], "source": [ - "# third party\n", - "from job_helpers import save_jobs" + "# syft absolute\n", + "from syft.util.test_helpers.job_helpers import save_jobs" ] }, { diff --git a/notebooks/scenarios/bigquery/040-do-review-requests.ipynb b/notebooks/scenarios/bigquery/040-do-review-requests.ipynb index aa4a7b0c2a1..8acc4e55274 100644 --- a/notebooks/scenarios/bigquery/040-do-review-requests.ipynb +++ b/notebooks/scenarios/bigquery/040-do-review-requests.ipynb @@ -18,21 +18,16 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "import random\n", "\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", "from syft.service.job.job_stash import Job\n", - "\n", - "# third party\n", - "from email_helpers import get_email_server\n", - "from job_helpers import approve_by_running\n", - "from job_helpers import get_job_emails\n", - "from job_helpers import get_request_for_job_info\n", - "# isort: on" + "from syft.util.test_helpers.email_helpers import get_email_server\n", + "from syft.util.test_helpers.job_helpers import approve_by_running\n", + "from syft.util.test_helpers.job_helpers import get_job_emails\n", + "from syft.util.test_helpers.job_helpers import get_request_for_job_info" ] }, { @@ -100,10 +95,10 @@ "metadata": {}, "outputs": [], "source": [ - "# third party\n", - "from email_helpers import load_users\n", - "from job_helpers import load_jobs\n", - "from job_helpers import save_jobs" + "# syft absolute\n", + "from syft.util.test_helpers.email_helpers import load_users\n", + "from syft.util.test_helpers.job_helpers import load_jobs\n", + "from syft.util.test_helpers.job_helpers import save_jobs" ] }, { diff --git a/notebooks/scenarios/bigquery/050-ds-get-results.ipynb b/notebooks/scenarios/bigquery/050-ds-get-results.ipynb index 9a9bc1ef588..35791771b2f 100644 --- a/notebooks/scenarios/bigquery/050-ds-get-results.ipynb +++ b/notebooks/scenarios/bigquery/050-ds-get-results.ipynb @@ -18,17 +18,12 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", - "\n", - "# third party\n", - "from email_helpers import get_email_server\n", - "from email_helpers import load_users\n", - "from job_helpers import load_jobs\n", - "from job_helpers import save_jobs\n", - "# isort: on" + "from syft.util.test_helpers.email_helpers import get_email_server\n", + "from syft.util.test_helpers.email_helpers import load_users\n", + "from syft.util.test_helpers.job_helpers import load_jobs\n", + "from syft.util.test_helpers.job_helpers import save_jobs" ] }, { diff --git a/notebooks/scenarios/bigquery/sync/01-setup-high-low-datasites.ipynb b/notebooks/scenarios/bigquery/sync/01-setup-high-low-datasites.ipynb index 633a73c38e4..691c58d4b00 100644 --- a/notebooks/scenarios/bigquery/sync/01-setup-high-low-datasites.ipynb +++ b/notebooks/scenarios/bigquery/sync/01-setup-high-low-datasites.ipynb @@ -42,15 +42,15 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# syft absolute\n", "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", "from syft import test_settings\n", - "\n", - "from worker_helpers import build_and_launch_worker_pool_from_docker_str\n", - "from worker_helpers import launch_worker_pool_from_docker_tag_and_registry\n", - "# isort: on" + "from syft.util.test_helpers.worker_helpers import (\n", + " build_and_launch_worker_pool_from_docker_str,\n", + ")\n", + "from syft.util.test_helpers.worker_helpers import (\n", + " launch_worker_pool_from_docker_tag_and_registry,\n", + ")" ] }, { diff --git a/notebooks/scenarios/bigquery/sync/02-configure-api-and-sync.ipynb b/notebooks/scenarios/bigquery/sync/02-configure-api-and-sync.ipynb index 094841ef58e..99274aba2a8 100644 --- a/notebooks/scenarios/bigquery/sync/02-configure-api-and-sync.ipynb +++ b/notebooks/scenarios/bigquery/sync/02-configure-api-and-sync.ipynb @@ -36,24 +36,21 @@ "metadata": {}, "outputs": [], "source": [ - "# isort: off\n", "# stdlib\n", "\n", - "# syft absolute\n", - "import syft as sy\n", - "from syft import test_helpers # noqa: F401\n", - "from syft import test_settings\n", - "from syft.client.syncing import compare_clients\n", - "\n", "# set to use the live APIs\n", "# import os\n", "# os.environ[\"TEST_BIGQUERY_APIS_LIVE\"] = \"True\"\n", "# third party\n", - "from apis import make_schema\n", - "from apis import make_submit_query\n", - "from apis import make_test_query\n", "import pandas as pd\n", - "# isort: on" + "\n", + "# syft absolute\n", + "import syft as sy\n", + "from syft import test_settings\n", + "from syft.client.syncing import compare_clients\n", + "from syft.util.test_helpers.apis import make_schema\n", + "from syft.util.test_helpers.apis import make_submit_query\n", + "from syft.util.test_helpers.apis import make_test_query" ] }, { diff --git a/packages/syft/src/syft/__init__.py b/packages/syft/src/syft/__init__.py index fb0fdfa69b1..2534f22077e 100644 --- a/packages/syft/src/syft/__init__.py +++ b/packages/syft/src/syft/__init__.py @@ -154,14 +154,6 @@ def _test_settings() -> Any: return test_settings() -@module_property -def _test_helpers() -> None: - # relative - from .util.util import add_helper_path_to_python_path - - add_helper_path_to_python_path() - - @module_property def hello_baby() -> None: print("Hello baby!") diff --git a/packages/syft/src/syft/util/test_helpers/__init__.py b/packages/syft/src/syft/util/test_helpers/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_helpers/apis/__init__.py b/packages/syft/src/syft/util/test_helpers/apis/__init__.py similarity index 90% rename from test_helpers/apis/__init__.py rename to packages/syft/src/syft/util/test_helpers/apis/__init__.py index 7231b580696..e8221857fba 100644 --- a/test_helpers/apis/__init__.py +++ b/packages/syft/src/syft/util/test_helpers/apis/__init__.py @@ -1,10 +1,8 @@ # stdlib import os -# syft absolute -from syft.util.util import str_to_bool - # relative +from ...util import str_to_bool from .submit_query import make_submit_query env_var = "TEST_BIGQUERY_APIS_LIVE" diff --git a/packages/syft/src/syft/util/test_helpers/apis/live/__init__.py b/packages/syft/src/syft/util/test_helpers/apis/live/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_helpers/apis/live/schema.py b/packages/syft/src/syft/util/test_helpers/apis/live/schema.py similarity index 99% rename from test_helpers/apis/live/schema.py rename to packages/syft/src/syft/util/test_helpers/apis/live/schema.py index 5b39d9d9066..7a63ab467d1 100644 --- a/test_helpers/apis/live/schema.py +++ b/packages/syft/src/syft/util/test_helpers/apis/live/schema.py @@ -3,9 +3,9 @@ # syft absolute import syft as sy -from syft import test_settings # relative +from ..... import test_settings from ..rate_limiter import is_within_rate_limit diff --git a/test_helpers/apis/live/test_query.py b/packages/syft/src/syft/util/test_helpers/apis/live/test_query.py similarity index 99% rename from test_helpers/apis/live/test_query.py rename to packages/syft/src/syft/util/test_helpers/apis/live/test_query.py index 344879dcb62..cca61eae533 100644 --- a/test_helpers/apis/live/test_query.py +++ b/packages/syft/src/syft/util/test_helpers/apis/live/test_query.py @@ -3,9 +3,9 @@ # syft absolute import syft as sy -from syft import test_settings # relative +from ..... import test_settings from ..rate_limiter import is_within_rate_limit diff --git a/packages/syft/src/syft/util/test_helpers/apis/mock/__init__.py b/packages/syft/src/syft/util/test_helpers/apis/mock/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_helpers/apis/mock/data.py b/packages/syft/src/syft/util/test_helpers/apis/mock/data.py similarity index 100% rename from test_helpers/apis/mock/data.py rename to packages/syft/src/syft/util/test_helpers/apis/mock/data.py diff --git a/test_helpers/apis/mock/schema.py b/packages/syft/src/syft/util/test_helpers/apis/mock/schema.py similarity index 100% rename from test_helpers/apis/mock/schema.py rename to packages/syft/src/syft/util/test_helpers/apis/mock/schema.py diff --git a/test_helpers/apis/mock/test_query.py b/packages/syft/src/syft/util/test_helpers/apis/mock/test_query.py similarity index 100% rename from test_helpers/apis/mock/test_query.py rename to packages/syft/src/syft/util/test_helpers/apis/mock/test_query.py diff --git a/test_helpers/apis/rate_limiter.py b/packages/syft/src/syft/util/test_helpers/apis/rate_limiter.py similarity index 100% rename from test_helpers/apis/rate_limiter.py rename to packages/syft/src/syft/util/test_helpers/apis/rate_limiter.py diff --git a/test_helpers/apis/submit_query.py b/packages/syft/src/syft/util/test_helpers/apis/submit_query.py similarity index 100% rename from test_helpers/apis/submit_query.py rename to packages/syft/src/syft/util/test_helpers/apis/submit_query.py diff --git a/test_helpers/email_helpers.py b/packages/syft/src/syft/util/test_helpers/email_helpers.py similarity index 98% rename from test_helpers/email_helpers.py rename to packages/syft/src/syft/util/test_helpers/email_helpers.py index f58d41a20f8..ddfee82fef3 100644 --- a/test_helpers/email_helpers.py +++ b/packages/syft/src/syft/util/test_helpers/email_helpers.py @@ -11,8 +11,8 @@ from aiosmtpd.controller import Controller from faker import Faker -# syft absolute -from syft.service.user.user_roles import ServiceRole +# relative +from ...service.user.user_roles import ServiceRole fake = Faker() @@ -162,7 +162,7 @@ def get_token(self) -> str: try: token = get_token(email) break - except Exception: + except Exception: # nosec pass self.reset_token = token return token @@ -220,7 +220,7 @@ def user_exists(root_client, email: str) -> bool: class SMTPTestServer: def __init__(self, email_server): self.port = 9025 - self.hostname = "0.0.0.0" + self.hostname = "0.0.0.0" # nosec: B104 self._stop_event = asyncio.Event() # Simple email handler class diff --git a/test_helpers/job_helpers.py b/packages/syft/src/syft/util/test_helpers/job_helpers.py similarity index 94% rename from test_helpers/job_helpers.py rename to packages/syft/src/syft/util/test_helpers/job_helpers.py index 78494d381e7..bac08bad5d6 100644 --- a/test_helpers/job_helpers.py +++ b/packages/syft/src/syft/util/test_helpers/job_helpers.py @@ -10,13 +10,11 @@ import textwrap from typing import Any -# third party -from email_helpers import TestUser +# relative +from ... import test_settings +from .email_helpers import TestUser -# syft absolute -from syft import test_settings - -from syft.client.client import SyftClient # noqa +from ...client.client import SyftClient # noqa dataset_1 = test_settings.get("dataset_1", default="dataset_1") dataset_2 = test_settings.get("dataset_2", default="dataset_2") @@ -87,7 +85,7 @@ def make_query(settings: dict) -> str: SELECT {settings['groupby_col']}, AVG({settings['score_col']}) AS average_score FROM {settings['dataset']}.{settings['table']} GROUP BY {settings['groupby_col']} - LIMIT {settings['limit']}""".strip() + LIMIT {settings['limit']}""".strip() # nosec: B608 return textwrap.dedent(query) @@ -96,14 +94,14 @@ def create_simple_query_job(user: TestUser) -> TestJob: job_type = "simple_query" func_name = f"{job_type}_{secrets.token_hex(3)}" - dataset = random.choice([dataset_1, dataset_2]) - table, groupby_col, score_col = random.choice( + dataset = random.choice([dataset_1, dataset_2]) # nosec: B311 + table, groupby_col, score_col = random.choice( # nosec: B311 [ (table_1, table_1_col_id, table_1_col_score), (table_2, table_2_col_id, table_2_col_score), ] ) - limit = random.randint(1, 1_000_000) + limit = random.randint(1, 1_000_000) # nosec: B311 settings = { "dataset": dataset, @@ -133,7 +131,7 @@ def create_wrong_asset_query(user: TestUser) -> TestJob: valid_job = create_simple_query_job(user) settings = valid_job.settings - corrupted_asset = random.choice(["dataset", "table"]) + corrupted_asset = random.choice(["dataset", "table"]) # nosec: B311 settings[corrupted_asset] = "wrong_asset" query = make_query(settings) @@ -240,7 +238,7 @@ def create_job_many_columns(user: TestUser) -> TestJob: job.job_type = job_type job.func_name = func_name settings = job.settings - job.settings["num_extra_cols"] = random.randint(100, 1000) + job.settings["num_extra_cols"] = random.randint(100, 1000) # nosec: B311 new_columns_string = ", ".join( f"{settings['score_col']} as col_{i}" for i in range(settings["num_extra_cols"]) @@ -250,13 +248,13 @@ def create_job_many_columns(user: TestUser) -> TestJob: SELECT {settings['groupby_col']}, AVG({settings['score_col']}) AS average_score, {new_columns_string} FROM {settings['dataset']}.{settings['table']} GROUP BY {settings['groupby_col']} - LIMIT {settings['limit']}""".strip() + LIMIT {settings['limit']}""".strip() # nosec: B608 return job def create_random_job(user: TestUser) -> TestJob: - job_func = random.choice(create_job_functions) + job_func = random.choice(create_job_functions) # nosec: B311 return job_func(user) diff --git a/test_helpers/sync_helpers.py b/packages/syft/src/syft/util/test_helpers/sync_helpers.py similarity index 92% rename from test_helpers/sync_helpers.py rename to packages/syft/src/syft/util/test_helpers/sync_helpers.py index e1d558016ba..7252b896ea2 100644 --- a/test_helpers/sync_helpers.py +++ b/packages/syft/src/syft/util/test_helpers/sync_helpers.py @@ -3,15 +3,17 @@ # syft absolute import syft as sy -from syft.client.datasite_client import DatasiteClient -from syft.client.syncing import compare_clients -from syft.service.code.user_code import UserCode -from syft.service.job.job_stash import Job -from syft.service.job.job_stash import JobStatus -from syft.service.request.request import Request -from syft.service.request.request import RequestStatus -from syft.service.sync.diff_state import ObjectDiffBatch -from syft.types.result import Err + +# relative +from ...client.datasite_client import DatasiteClient +from ...client.syncing import compare_clients +from ...service.code.user_code import UserCode +from ...service.job.job_stash import Job +from ...service.job.job_stash import JobStatus +from ...service.request.request import Request +from ...service.request.request import RequestStatus +from ...service.sync.diff_state import ObjectDiffBatch +from ...types.result import Err def deny_requests_without_autosync_tag(client_low: DatasiteClient): diff --git a/packages/syft/src/syft/util/test_helpers/worker_helpers.py b/packages/syft/src/syft/util/test_helpers/worker_helpers.py new file mode 100644 index 00000000000..3c2667fecc8 --- /dev/null +++ b/packages/syft/src/syft/util/test_helpers/worker_helpers.py @@ -0,0 +1,86 @@ +# syft absolute +import syft as sy + + +def build_and_launch_worker_pool_from_docker_str( + environment: str, + client: sy.DatasiteClient, + worker_pool_name: str, + custom_pool_pod_annotations: dict, + custom_pool_pod_labels: dict, + worker_dockerfile: str, + external_registry: str, + docker_tag: str, + scale_to: int, +): + result = client.api.services.image_registry.add(external_registry) + assert "success" in result.message # nosec: B101 + + # For some reason, when using k9s, result.value is empty so can't use the below line + # local_registry = result.value + local_registry = client.api.services.image_registry[0] + + docker_config = sy.DockerWorkerConfig(dockerfile=worker_dockerfile) + assert docker_config.dockerfile == worker_dockerfile # nosec: B101 + submit_result = client.api.services.worker_image.submit(worker_config=docker_config) + print(submit_result.message) + assert "success" in submit_result.message # nosec: B101 + + worker_image = submit_result.value + + if environment == "remote": + docker_build_result = client.api.services.worker_image.build( + image_uid=worker_image.id, + tag=docker_tag, + registry_uid=local_registry.id, + ) + print(docker_build_result) + + if environment == "remote": + push_result = client.api.services.worker_image.push(worker_image.id) + print(push_result) + + result = client.api.services.worker_pool.launch( + pool_name=worker_pool_name, + image_uid=worker_image.id, + num_workers=1, + pod_annotations=custom_pool_pod_annotations, + pod_labels=custom_pool_pod_labels, + ) + print(result) + # assert 'success' in str(result.message) + + if environment == "remote": + result = client.worker_pools.scale(number=scale_to, pool_name=worker_pool_name) + print(result) + + +def launch_worker_pool_from_docker_tag_and_registry( + environment: str, + client: sy.DatasiteClient, + worker_pool_name: str, + custom_pool_pod_annotations: dict, + custom_pool_pod_labels: dict, + docker_tag: str, + external_registry: str, + scale_to: int = 1, +): + res = client.api.services.image_registry.add(external_registry) + assert "success" in res.message # nosec: B101 + docker_config = sy.PrebuiltWorkerConfig(tag=docker_tag) + image_result = client.api.services.worker_image.submit(worker_config=docker_config) + assert "success" in res.message # nosec: B101 + worker_image = image_result.value + + launch_result = client.api.services.worker_pool.launch( + pool_name=worker_pool_name, + image_uid=worker_image.id, + num_workers=1, + pod_annotations=custom_pool_pod_annotations, + pod_labels=custom_pool_pod_labels, + ) + if environment == "remote" and scale_to > 1: + result = client.worker_pools.scale(number=scale_to, pool_name=worker_pool_name) + print(result) + + return launch_result diff --git a/packages/syft/src/syft/util/util.py b/packages/syft/src/syft/util/util.py index 83efaa196e7..fa20c3fc2c2 100644 --- a/packages/syft/src/syft/util/util.py +++ b/packages/syft/src/syft/util/util.py @@ -1143,21 +1143,6 @@ def test_settings() -> Any: return test_settings -def add_helper_path_to_python_path() -> None: - current_path = "." - - # jupyter uses "." which resolves to the notebook - if not is_interpreter_jupyter(): - # python uses the file which has from syft import test_settings in it - import_path = get_caller_file_path() - if import_path: - current_path = import_path - - base_dir = find_base_dir_with_tox_ini(current_path) - notebook_helper_path = os.path.join(base_dir, "test_helpers") - sys.path.append(notebook_helper_path) - - class CustomRepr(reprlib.Repr): def repr_str(self, obj: Any, level: int = 0) -> str: if len(obj) <= self.maxstring: diff --git a/tests/scenarios/bigquery/level_2_basic_test.py b/tests/scenarios/bigquery/level_2_basic_test.py index 6f4f4372ad7..e3c6f18379a 100644 --- a/tests/scenarios/bigquery/level_2_basic_test.py +++ b/tests/scenarios/bigquery/level_2_basic_test.py @@ -41,6 +41,13 @@ from syft.service.job.job_stash import Job +def test_check_test_helper_module_import(): + # syft absolute + from syft.util.test_helpers.email_helpers import SENDER + + assert SENDER == "noreply@openmined.org" + + @unsync async def get_prebuilt_worker_image(events, client, expected_tag, event_name): await events.await_for(event_name=event_name, show=True) diff --git a/tox.ini b/tox.ini index 15353917ac2..6a54b437098 100644 --- a/tox.ini +++ b/tox.ini @@ -380,6 +380,7 @@ deps = nbmake db-dtypes google-cloud-bigquery + aiosmtpd changedir = {toxinidir}/notebooks allowlist_externals = bash @@ -494,6 +495,7 @@ deps = nbmake db-dtypes google-cloud-bigquery + aiosmtpd changedir = {toxinidir}/notebooks allowlist_externals = bash