Skip to content

Commit

Permalink
try with App.run_command()
Browse files Browse the repository at this point in the history
  • Loading branch information
hswong3i committed Jan 22, 2025
1 parent 658b2b6 commit 31e3440
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run_command(cmd, env=os.environ, log=True):
if log:
cmd = _rebake_command(cmd, env)
cmd = cmd.bake(_truncate_exc=False)
return app.run_command(cmd, env=env)
return App.run_command(cmd, env=env)


def _rebake_command(cmd, env, out=LOG.info, err=LOG.error):
Expand Down
2 changes: 1 addition & 1 deletion src/molecule_plugins/podman/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,4 @@ def required_collections(self) -> dict[str, str]:

def reset(self):
# keep `--filter` in sync with playbooks/create.yml
app.run_command(["podman", "rm", "--force", "--filter=label=owner=molecule"])
App.run_command(["podman", "rm", "--force", "--filter=label=owner=molecule"])
10 changes: 5 additions & 5 deletions test/azure/functional/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
def test_azure_command_init_scenario(temp_dir):
role_directory = os.path.join(temp_dir.strpath, "test_init")
cmd = ["ansible-galaxy", "role", "init", "test_init"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

with change_dir_to(role_directory):
Expand All @@ -47,7 +47,7 @@ def test_azure_command_init_scenario(temp_dir):
"-a",
'path=meta/main.yml line=" namespace: foo" insertafter=" author: your name"',
]
app.run_command(cmd_meta, check=True)
App.run_command(cmd_meta, check=True)

# we need to inject namespace info into tests/test.yml
cmd_tests = [
Expand All @@ -59,7 +59,7 @@ def test_azure_command_init_scenario(temp_dir):
"-a",
'path=tests/test.yml line=" - foo.test_init" regex="^(.*) - test_init"',
]
app.run_command(cmd_tests, check=True)
App.run_command(cmd_tests, check=True)

molecule_directory = pytest.helpers.molecule_directory()
scenario_directory = os.path.join(molecule_directory, "test_scenario")
Expand All @@ -71,7 +71,7 @@ def test_azure_command_init_scenario(temp_dir):
"--driver-name",
"azure",
]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

assert os.path.isdir(scenario_directory)
Expand All @@ -82,5 +82,5 @@ def test_azure_command_init_scenario(temp_dir):
# temporary trick to pass on CI/CD
if "AZURE_SECRET" in os.environ:
cmd = ["molecule", "test", "-s", "test-scenario"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0
4 changes: 2 additions & 2 deletions test/containers/functional/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_containers_command_init_scenario(temp_dir):
"--driver-name",
"containers",
]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

assert os.path.isdir(scenario_directory)
Expand All @@ -49,5 +49,5 @@ def test_containers_command_init_scenario(temp_dir):
# is shorter but comprehensive enough to test the most important
# functionality: destroy, dependency, create, prepare, converge
cmd = ["molecule", "check", "-s", "default"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0
14 changes: 7 additions & 7 deletions test/docker/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ def test_command_init_and_test_scenario(tmp_path: pathlib.Path, DRIVER: str) ->
"--driver-name",
DRIVER,
]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

assert scenario_directory.exists()

# run molecule reset as this may clean some leftovers from other
# test runs and also ensure that reset works.
result = app.run_command(["molecule", "reset"]) # default scenario
result = App.run_command(["molecule", "reset"]) # default scenario
assert result.returncode == 0

result = app.run_command(["molecule", "reset", "-s", scenario_name])
result = App.run_command(["molecule", "reset", "-s", scenario_name])
assert result.returncode == 0

cmd = ["molecule", "--debug", "test", "-s", scenario_name]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0


Expand All @@ -63,7 +63,7 @@ def test_command_static_scenario() -> None:
"""Validate that the scenario we included with code still works."""
cmd = ["molecule", "test"]

result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0


Expand All @@ -72,7 +72,7 @@ def test_dockerfile_with_context() -> None:
"""Verify that Dockerfile.j2 with context works."""
with change_dir_to("test/docker/scenarios/with-context"):
cmd = ["molecule", "--debug", "test"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0


Expand All @@ -82,5 +82,5 @@ def test_env_substitution() -> None:
os.environ["MOLECULE_ROLE_IMAGE"] = "debian:bullseye"
with change_dir_to("test/docker/scenarios/env-substitution"):
cmd = ["molecule", "--debug", "test"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0
6 changes: 3 additions & 3 deletions test/ec2/functional/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
def test_ec2_command_init_scenario(temp_dir):
role_directory = os.path.join(temp_dir.strpath, "test-init")
cmd = ["molecule", "init", "role", "test-init"]
assert app.run_command(cmd).returncode == 0
assert App.run_command(cmd).returncode == 0
metadata_lint_update(role_directory)

with change_dir_to(role_directory):
Expand All @@ -48,11 +48,11 @@ def test_ec2_command_init_scenario(temp_dir):
"--role_name=test-init",
"--driver-name=ec2",
]
assert app.run_command(cmd).returncode == 0
assert App.run_command(cmd).returncode == 0

assert os.path.isdir(scenario_directory)
os.unlink(os.path.join(scenario_directory, "create.yml"))
os.unlink(os.path.join(scenario_directory, "destroy.yml"))

cmd = ["molecule", "test", "-s", "test-scenario"]
assert app.run_command(cmd).returncode == 0
assert App.run_command(cmd).returncode == 0
6 changes: 3 additions & 3 deletions test/gce/functional/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_gce_command_init_scenario(temp_dir):
"""Test init scenario with driver."""
role_directory = os.path.join(temp_dir.strpath, "test-init")
cmd = ["molecule", "init", "role", "test-init"]
assert app.run_command(cmd).returncode == 0
assert App.run_command(cmd).returncode == 0
metadata_lint_update(role_directory)

with change_dir_to(role_directory):
Expand All @@ -52,11 +52,11 @@ def test_gce_command_init_scenario(temp_dir):
"--driver-name",
driver_name,
]
assert app.run_command(cmd).returncode == 0
assert App.run_command(cmd).returncode == 0

assert os.path.isdir(scenario_directory)
os.unlink(os.path.join(scenario_directory, "create.yml"))
os.unlink(os.path.join(scenario_directory, "destroy.yml"))

cmd = ["molecule", "test", "-s", "test-scenario"]
assert app.run_command(cmd).returncode == 0
assert App.run_command(cmd).returncode == 0
6 changes: 3 additions & 3 deletions test/openstack/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_openstack_init_and_test_scenario(tmp_path: pathlib.Path, DRIVER: str) -
"--driver-name",
DRIVER,
]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

assert scenario_directory.exists()
Expand All @@ -71,7 +71,7 @@ def test_openstack_init_and_test_scenario(tmp_path: pathlib.Path, DRIVER: str) -
shutil.copyfile(testconf, confpath)

cmd = ["molecule", "--debug", "test", "-s", scenario_name]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0


Expand All @@ -86,5 +86,5 @@ def test_specific_scenarios(temp_dir, scenario) -> None:

with change_dir_to(scenario_directory):
cmd = ["molecule", "test", "--scenario-name", scenario]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0
10 changes: 5 additions & 5 deletions test/podman/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ def test_podman_command_init_scenario(tmp_path: pathlib.Path):
"--driver-name",
"podman",
]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

assert scenario_directory.exists()

# run molecule reset as this may clean some leftovers from other
# test runs and also ensure that reset works.
result = app.run_command(["molecule", "reset"]) # default sceanario
result = App.run_command(["molecule", "reset"]) # default sceanario
assert result.returncode == 0

result = app.run_command(["molecule", "reset", "-s", scenario_name])
result = App.run_command(["molecule", "reset", "-s", scenario_name])
assert result.returncode == 0

cmd = ["molecule", "--debug", "test", "-s", scenario_name]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0


def test_sample() -> None:
"""Runs the sample scenario present at the repository root."""
result = app.run_command(["molecule", "test", "-s", "test-podman"]) # default sceanario
result = App.run_command(["molecule", "test", "-s", "test-podman"]) # default sceanario
assert result.returncode == 0


Expand Down
10 changes: 5 additions & 5 deletions test/vagrant-plugin/functional/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_vagrant_command_init_scenario(temp_dir):
"--driver-name",
"vagrant",
]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

assert os.path.isdir(scenario_directory)
Expand All @@ -77,7 +77,7 @@ def test_vagrant_command_init_scenario(temp_dir):
conf["driver"]["provider"] = {"name": "libvirt"}
util.write_file(confpath, util.safe_dump(conf))
cmd = ["molecule", "--debug", "test", "-s", "test-scenario"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0


Expand All @@ -94,7 +94,7 @@ def test_invalid_settings(temp_dir):

with change_dir_to(scenario_directory):
cmd = ["molecule", "create", "--scenario-name", "invalid"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 2

assert "Failed to validate generated Vagrantfile" in result.stdout
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_vagrant_root(temp_dir, scenario):

with change_dir_to(scenario_directory):
cmd = ["molecule", "test", "--scenario-name", scenario]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0


Expand All @@ -143,7 +143,7 @@ def test_multi_node(temp_dir):

with change_dir_to(scenario_directory):
cmd = ["molecule", "test", "--scenario-name", "multi-node"]
result = app.run_command(cmd)
result = App.run_command(cmd)
assert result.returncode == 0

molecule_eph_directory = ephemeral_directory()
Expand Down

0 comments on commit 31e3440

Please sign in to comment.