def test_provision_when_no_conda_env_exists(context: dict, env_name: str, caplog): """Test to run the provision command when the conda environment does not exist""" caplog.set_level(logging.DEBUG) # GIVEN that the specified conda environment does not exist assert conda_env_exists(env_name) is False # GIVEN a cli runner runner = CliRunner() # WHEN running the provision command result = runner.invoke(provision_cmd, [], obj=context) # THEN assert that the commands with a zero exit code assert result.exit_code == 0 # THEN assert that the environment was created assert conda_env_exists(env_name) is True
def test_check_cmd_no_environment(env_name: str, context: dict, caplog): """Test to run the check command when the environment does not exist""" caplog.set_level(logging.DEBUG) # GIVEN a environment that does not exist delete_conda_env(Process("conda"), env_name) assert conda_env_exists(env_name) is False # GIVEN a cli runner runner = CliRunner() # GIVEN a context with basic information # WHEN running the command to check if deployment is possible runner.invoke(check_cmd, [], obj=context) # THEN assert that it communicates that the environment does not exist assert "Please use 'shipping provision' to create valid conda environment" in caplog.text
def test_deploy_existing_env(other_env: str, context: dict, caplog): """Test to deploy a package when the environment exists""" caplog.set_level(logging.DEBUG) # GIVEN that the environment does exist assert conda_env_exists(other_env) is True # GIVEN a cli runner runner = CliRunner() # WHEN deploying the tool result = runner.invoke(deploy_cmd, [], obj=context) # THEN assert that the program exits with a zero exit code assert result.exit_code == 0 # THEN assert that the correct information is communicated assert "Tool was successfully deployed" in caplog.text
def test_provision_when_env_already_exists(context: dict, other_env: str, caplog): """Test to run the provision command when the conda environment exists""" caplog.set_level(logging.DEBUG) # GIVEN that the specified conda environment already exists assert conda_env_exists(other_env) is True # GIVEN a cli runner runner = CliRunner() # WHEN running the provision command result = runner.invoke(provision_cmd, [], obj=context) # THEN assert that the commands with a zero exit code assert result.exit_code == 0 # THEN assert that the commands with a zero exit code assert f"Environment {other_env} already exists" in caplog.text
def test_deploy_non_existing_env(env_name: str, context: dict, caplog): """Test to deploy a package when an environment does not exist""" caplog.set_level(logging.DEBUG) # GIVEN that the environment does not exist delete_conda_env(Process("conda"), env_name) assert conda_env_exists(env_name) is False # GIVEN a cli runner runner = CliRunner() # WHEN deploying the tool result = runner.invoke(deploy_cmd, [], obj=context) # THEN assert that the program exits with a non zero exit code assert result.exit_code != 0 # THEN assert that the correct information is communicated assert f"Environment {env_name} does not exist" in caplog.text
def check_if_deploy_possible(conda_env_name: str) -> bool: """Function to check if conda requirements are fulfilled for deployment 1. Check if conda is available 2. Check if the environment exists """ LOG.info("Check if conda is available on your system") if not environment.conda_exists(): LOG.warning("Please make sure conda is available") return False LOG.info("You are in conda environment %s", environment.get_conda_name()) package_env = environment.get_conda_path(env_name=conda_env_name) LOG.info("You want to install in conda environment %s", package_env) if not environment.conda_env_exists(conda_env_name): LOG.warning("Environment %s does not exist", conda_env_name) return False return True
def test_deploy_with_log_file(other_env: str, log_file_context: dict, caplog): """Test to deploy a package when the environment exists""" caplog.set_level(logging.DEBUG) # GIVEN that the environment does exist assert conda_env_exists(other_env) is True # GIVEN a cli runner runner = CliRunner() # GIVEN that an existing empty log file is used log_path: Path = log_file_context["host_config"].log_path assert log_path.exists() with open(log_path, "r") as infile: content = infile.read() assert not content # WHEN deploying the tool result = runner.invoke(deploy_cmd, [], obj=log_file_context) # THEN assert that the log message was printed to the file with open(log_path, "r") as infile: content = infile.read() assert content
def test_check_cmd_environment_exists( populated_env: str, context: dict, tool_name: str, other_python_process: Process, caplog ): """Test to run the check command when the environment does exist""" caplog.set_level(logging.DEBUG) env_name = populated_env # GIVEN a environment that does exist assert conda_env_exists(env_name) is True # GIVEN that the tool is already installed in the environment version = fetch_package_version(python_process=other_python_process, package_name=tool_name) assert version # GIVEN a cli runner runner = CliRunner() # GIVEN a context with basic information # WHEN running the command to check if deployment is possible result = runner.invoke(check_cmd, [], obj=context) # THEN assert that the tool name is in the log line that was produced assert tool_name in result.output # THEN assert that the tool version is in the log line that was produced assert version in result.output