Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
test: enable tests on charmcraft package (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsgruk authored Jan 15, 2024
1 parent b9fe8f0 commit b436b0c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 30 deletions.
42 changes: 36 additions & 6 deletions apps/charmcraft/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ pkgs.python3Packages.buildPythonApplication {
hash = "sha256-u4Bn2skW2uGz34Yu30qTlDlFUIqB9izhzmZOZr67IcQ=";
};

patches = [
./set-channel-for-nix.patch
];

postPatch = ''
substituteInPlace \
setup.py \
Expand Down Expand Up @@ -48,8 +44,42 @@ pkgs.python3Packages.buildPythonApplication {
tabulate
];

# TODO: Try to make the tests pass and remove this.
doCheck = false;
preCheck = ''
mkdir -p check-phase
export HOME=$(pwd)/check-phase
'';

nativeCheckInputs = with pkgs.python3Packages; [
flake8
pydocstyle
pyfakefs
pytest-check
pytest-mock
pytest-subprocess
pytestCheckHook
responses
] ++ (with pkgs; [
git
]);

disabledTests = [
# Relies upon the `charm` tool being installed
"test_validate_missing_charm"
# This tests something which is patched out anyway
"test_setup_version"
"test_localdockerinterface_get_streamed_content"
# Relies upon building a venv using an internet connection, and running
# commands in tox.
"test_tests"
# Pydantic model violations - fail because tests rely upon host system
# attributes being compatible with Ubuntu.
"test_build_error_without_metadata_yaml"
"test_build_checks_provider"
"test_build_checks_provider_error"
"test_build_postlifecycle_validation_is_properly_called"
"test_build_part_from_config"
"test_build_part_include_venv_pydeps"
];

meta = {
description = "Build and publish Charmed Operators";
Expand Down
23 changes: 0 additions & 23 deletions apps/charmcraft/set-channel-for-nix.patch

This file was deleted.

30 changes: 30 additions & 0 deletions deps/craft-parts/bash-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/craft_parts/executor/step_handler.py b/craft_parts/executor/step_handler.py
index 404df69..60e5aba 100644
--- a/craft_parts/executor/step_handler.py
+++ b/craft_parts/executor/step_handler.py
@@ -394,7 +394,8 @@ def _create_and_run_script(
) -> None:
"""Create a script with step-specific commands and execute it."""
with script_path.open("w") as run_file:
- print("#!/bin/bash", file=run_file)
+ import shutil
+ print(f"#!{shutil.which('bash')}", file=run_file)
print("set -euo pipefail", file=run_file)

if build_environment_script_path:
diff --git a/craft_parts/plugins/validator.py b/craft_parts/plugins/validator.py
index b8d8f11..fce0e72 100644
--- a/craft_parts/plugins/validator.py
+++ b/craft_parts/plugins/validator.py
@@ -142,9 +142,9 @@ class PluginEnvironmentValidator:
print(self._env, file=env_file)
print(cmd, file=env_file)
env_file.flush()
-
+ import shutil
proc = subprocess.run(
- ["/bin/bash", env_file.name],
+ [shutil.which("bash"), env_file.name],
check=True,
capture_output=True,
text=True,
4 changes: 4 additions & 0 deletions deps/craft-parts.nix → deps/craft-parts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pkgs.python3Packages.buildPythonPackage rec {
sha256 = "sha256-Q0GMiglo16mvJUBDhy4cnWjFiHCsW61QsZkhejCjvsE=";
};

patches = [
./bash-path.patch
];

propagatedBuildInputs = with pkgs.python3Packages;[
overrides
pydantic
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
craft-archives = final.callPackage ./deps/craft-archives.nix { };
craft-cli = final.callPackage ./deps/craft-cli.nix { };
craft-grammar = final.callPackage ./deps/craft-grammar.nix { };
craft-parts = final.callPackage ./deps/craft-parts.nix { };
craft-parts = final.callPackage ./deps/craft-parts { };
craft-providers = final.callPackage ./deps/craft-providers { };
craft-store = final.callPackage ./deps/craft-store.nix { };
gnupg = final.callPackage ./deps/gnupg.nix { };
Expand Down

0 comments on commit b436b0c

Please sign in to comment.