-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(bors): merge pull request #564
564: Upgrade basic sanity test r=niladrih a=niladrih Changes: - Adds a pytest for testing basic sanity in upgrade - Add enhancement to the scripts/helm/install.sh script to support installing from a hosted registry - Add a script to format python files Co-authored-by: Niladri Halder <[email protected]>
- Loading branch information
Showing
14 changed files
with
677 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,6 @@ __pycache__ | |
/kubectl-plugin | ||
|
||
# Pytest assets | ||
/test-bin-* | ||
/test-dir-* | ||
tests/bdd/venv | ||
pytest.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[pytest] | ||
log_cli = true | ||
log_cli_level = INFO | ||
log_cli_format = %(asctime)s [%(levelname)s] %(message)s | ||
log_cli_date_format = %Y-%m-%d %H:%M:%S | ||
log_file = pytest.log | ||
log_file_level = DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env bash | ||
|
||
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")" | ||
ROOT_DIR="$SCRIPT_DIR/../.." | ||
|
||
# Imports | ||
source "$ROOT_DIR"/scripts/utils/log.sh | ||
|
||
set -e | ||
|
||
fmt() { | ||
local -r paths_glob=$1 | ||
|
||
bash -c " | ||
black --quiet $paths_glob && | ||
isort --profile=black --quiet $paths_glob && | ||
autoflake --quiet -r -i --remove-unused-variables --remove-all-unused-imports --expand-star-imports $paths_glob" | ||
} | ||
|
||
fmt_diff() { | ||
local -r paths_glob=($(bash -c "echo $1")) | ||
|
||
for path in "${paths_glob[@]}"; do | ||
find "$path" -type f -name "*.py" -exec bash -c ' | ||
OUTPUT=$(diff -u --color=always <(cat {}) <(black -c "$(cat {})" | | ||
isort --profile=black -d - | | ||
autoflake --remove-unused-variables --remove-all-unused-imports --expand-star-imports -s -) | ||
); | ||
if [ -n "$OUTPUT" ]; then | ||
echo -e "Diff for file {}\n===================================================\n$OUTPUT\n" | cat | ||
fi | ||
' \; | ||
done | ||
} | ||
|
||
fmt_check() { | ||
local -r paths_glob=$1 | ||
|
||
local error= | ||
bash -c " | ||
black --quiet $paths_glob --check && | ||
isort --profile=black --quiet $paths_glob --check 2> /dev/null && | ||
autoflake --quiet -r --remove-unused-variables --remove-all-unused-imports --expand-star-imports $paths_glob --check > /dev/null | ||
" || error=$? | ||
|
||
if [ -n "$error" ]; then | ||
exit $error | ||
fi | ||
exit 0 | ||
} | ||
|
||
CHECK= | ||
DIFF= | ||
PATHS_GLOB= | ||
DEFAULT_PATHS_GLOB=$(realpath "$ROOT_DIR"/tests/bdd)/{common,features} | ||
|
||
# Print usage options for this script. | ||
print_help() { | ||
cat <<EOF | ||
Usage: $(basename "${0}") [OPTIONS] | ||
Options: | ||
-h, --help Display this text. | ||
--check Don't write the files back, just return the status. | ||
Return code 0 means nothing would change. Return code | ||
1 means some files would be changed. | ||
--diff Don't write the files back, just output a diff to | ||
indicate what changes would've been made. | ||
--paths-glob <glob> Input a paths glob of directories and/or files which | ||
would be parsed recursively. (default: "$DEFAULT_PATHS_GLOB") | ||
Examples: | ||
$(basename "${0}") --check | ||
EOF | ||
} | ||
|
||
# Parse args. | ||
while test $# -gt 0; do | ||
arg="$1" | ||
case "$arg" in | ||
--check) | ||
CHECK=1 | ||
;; | ||
--diff) | ||
DIFF=1 | ||
;; | ||
--paths-glob*) | ||
if [ "$arg" = "--paths-glob" ]; then | ||
test $# -lt 2 && log_fatal "Missing value for the optional argument '$arg'." | ||
PATHS_GLOB="$2" | ||
shift | ||
else | ||
PATHS_GLOB="${arg#*=}" | ||
fi | ||
;; | ||
-h* | --help*) | ||
print_help | ||
exit 0 | ||
;; | ||
*) | ||
print_help | ||
log_fatal "unexpected argument '$arg'" 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ -z "$PATHS_GLOB" ]; then | ||
PATHS_GLOB=$DEFAULT_PATHS_GLOB | ||
fi | ||
|
||
if [ -n "$CHECK" ]; then | ||
fmt_check "$PATHS_GLOB" | ||
fi | ||
|
||
if [ -n "$DIFF" ]; then | ||
fmt_diff "$PATHS_GLOB" | ||
fi | ||
|
||
if [[ -z "$CHECK" ]] && [[ -z "$DIFF" ]]; then | ||
fmt "$PATHS_GLOB" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import logging | ||
import os | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_env(variable: str): | ||
try: | ||
value = os.getenv(variable) | ||
if len(value) == 0: | ||
raise ValueError("Env {variable} is empty") | ||
logger.info(f"Found env {variable}={value}") | ||
return value | ||
|
||
except Exception as e: | ||
logger.error(f"Failed to get env {variable}: {e}") | ||
return None |
Oops, something went wrong.