From 68367620d2db12c904af033858c54fab04bc9137 Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Fri, 22 Mar 2024 23:22:57 -0400 Subject: [PATCH] refactor: refines E2E ssp test for better readabilty Remove the redefinition of commands that would create the same output and removed missed subprocess line Signed-off-by: Jennifer Power --- Makefile | 2 +- tests/e2e/test_e2e_ssp.py | 61 ++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 86033b9a..8ab8f707 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ test-slow: .PHONY: test-slow test-e2e: - @poetry run pytest $(TESTS)/$(E2E) --slow --cov --cov-config=pyproject.toml --cov-report=xml + @poetry run pytest $(TESTS)/$(E2E) --slow --cov --cov-config=pyproject.toml --cov-report=xml -vvv .PHONY: test-e2e test-code-cov: diff --git a/tests/e2e/test_e2e_ssp.py b/tests/e2e/test_e2e_ssp.py index 06695cb9..26a541a2 100644 --- a/tests/e2e/test_e2e_ssp.py +++ b/tests/e2e/test_e2e_ssp.py @@ -19,7 +19,6 @@ import logging import os import pathlib -import subprocess from typing import Dict, Tuple import pytest @@ -91,25 +90,31 @@ def test_ssp_editing_e2e( args = setup_for_ssp(tmp_repo_path, test_prof, [test_comp_name], test_ssp_md) + # Get command arguments for the test + branch = command_args["branch"] + markdown_path = command_args["markdown-path"] + committer_name = command_args["committer-name"] + committer_email = command_args["committer-email"] + # Create or generate the SSP if not skip_create: create_args: Dict[str, str] = { - "markdown-path": command_args["markdown-path"], - "branch": command_args["branch"], - "committer-name": command_args["committer-name"], - "committer-email": command_args["committer-email"], + "markdown-path": markdown_path, + "branch": branch, + "committer-name": committer_name, + "committer-email": committer_email, "ssp-name": test_ssp_name, "profile-name": test_prof, "compdefs": test_comp_name, } - command = e2e_runner.build_test_command( + create_command = e2e_runner.build_test_command( tmp_repo_str, "create-ssp", create_args, ) - exit_code, _ = e2e_runner.invoke_command(command) + exit_code, _ = e2e_runner.invoke_command(create_command) assert exit_code == response - assert (tmp_repo_path / command_args["markdown-path"]).exists() + assert (tmp_repo_path / markdown_path).exists() # Make a change to the SSP ssp, ssp_path = ModelUtils.load_model_for_class( @@ -124,17 +129,15 @@ def test_ssp_editing_e2e( ssp_generate = SSPGenerate() assert ssp_generate._run(args) == 0 - command = e2e_runner.build_test_command(tmp_repo_str, "autosync", command_args) - run_response = subprocess.run(command, capture_output=True) - assert run_response.returncode == response + autosync_command = e2e_runner.build_test_command( + tmp_repo_str, "autosync", command_args + ) + exit_code, response_stdout = e2e_runner.invoke_command(autosync_command) + assert exit_code == response # Check that the ssp was pushed to the remote if response == SUCCESS_EXIT_CODE: - branch = command_args["branch"] - assert ( - f"Changes pushed to {branch} successfully." - in run_response.stdout.decode("utf-8") - ) + assert f"Changes pushed to {branch} successfully." in response_stdout # Check that the correct files are present with the correct content index_path = os.path.join(tmp_repo_str, "ssp-index.json") @@ -145,8 +148,7 @@ def test_ssp_editing_e2e( assert ssp_path.exists() # Check that if run again, the ssp is not pushed again - command = e2e_runner.build_test_command(tmp_repo_str, "autosync", command_args) - exit_code, response_stdout = e2e_runner.invoke_command(command) + exit_code, response_stdout = e2e_runner.invoke_command(autosync_command) assert exit_code == SUCCESS_EXIT_CODE assert "Nothing to commit" in response_stdout @@ -154,32 +156,25 @@ def test_ssp_editing_e2e( local_upstream_path = prepare_upstream_repo() upstream_repos_arg = f"{e2e_runner.UPSTREAM_REPO}@main" upstream_command_args = { - "branch": command_args["branch"], - "committer-name": command_args["committer-name"], - "committer-email": command_args["committer-email"], + "branch": branch, + "committer-name": committer_name, + "committer-email": committer_email, "sources": upstream_repos_arg, } - command = e2e_runner.build_test_command( + sync_upstreams_command = e2e_runner.build_test_command( tmp_repo_str, "sync-upstreams", upstream_command_args, local_upstream_path, ) - exit_code, response_stdout = e2e_runner.invoke_command(command) + exit_code, response_stdout = e2e_runner.invoke_command(sync_upstreams_command) assert exit_code == SUCCESS_EXIT_CODE - assert ( - f"Changes pushed to {command_args['branch']} successfully." - in run_response.stdout.decode("utf-8") - ) + assert f"Changes pushed to {branch} successfully." in response_stdout # Autosync again to check that the ssp is updated - command = e2e_runner.build_test_command(tmp_repo_str, "autosync", command_args) - exit_code, response_stdout = e2e_runner.invoke_command(command) + exit_code, response_stdout = e2e_runner.invoke_command(autosync_command) assert exit_code == SUCCESS_EXIT_CODE - assert ( - f"Changes pushed to {command_args['branch']} successfully." - in response_stdout - ) + assert f"Changes pushed to {branch} successfully." in response_stdout # Clean up the upstream repo clean(local_upstream_path, None)