Skip to content

Commit c140cc5

Browse files
feat: added github workflow that checks test file names (#1054) (#1096)
Signed-off-by: HusseinYasser <[email protected]>
1 parent 0e3f795 commit c140cc5

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
RED="\033[31m"
3+
YELLOW="\033[33m"
4+
RESET="\033[0m"
5+
6+
# Base directories where test files should reside
7+
TEST_DIRS=("tests/unit" "tests/integration")
8+
EXCEPTION_NAMES=("conftest.py" "init.py" "__init__.py" "mock_server.py" "utils.py")
9+
DIFF_FILES=$(git diff --name-status origin/main)
10+
ERRORS=()
11+
12+
function is_in_test_dir() {
13+
local file="$1"
14+
for dir in "${TEST_DIRS[@]}"; do
15+
case "$file" in
16+
"$dir"*)
17+
return 0
18+
;;
19+
esac
20+
done
21+
return 1
22+
}
23+
24+
function check_test_file_name() {
25+
local filename="$1"
26+
if is_in_test_dir "$filename"; then
27+
if [[ $(basename "$filename") != *.py ]]; then
28+
return 0
29+
fi
30+
for exception in "${EXCEPTION_NAMES[@]}"; do
31+
if [[ $(basename "$filename") == "$exception" ]]; then
32+
return 0
33+
fi
34+
done
35+
if [[ $(basename "$filename") != *_test.py ]]; then
36+
ERRORS+=("${RED}ERROR${RESET}: Test file '$filename' doesn't end with '_test.py'. ${YELLOW}It has to follow the pytest naming convention.")
37+
return 1
38+
fi
39+
fi
40+
return 0
41+
}
42+
43+
while IFS=$'\t' read -r status file1 file2; do
44+
case "$status" in
45+
A) check_test_file_name "$file1" ;;
46+
R*) check_test_file_name "$file2" ;;
47+
C*) check_test_file_name "$file2" ;;
48+
esac
49+
done <<< "$DIFF_FILES"
50+
51+
if (( ${#ERRORS[@]} > 0 )); then
52+
for err in "${ERRORS[@]}"; do
53+
echo -e "$err"
54+
done
55+
exit 1
56+
fi
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test Files Naming Check
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
8+
concurrency:
9+
group: pr-checks-${{ github.workflow }}-${{ github.ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
check-test-files:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
19+
20+
- name: Set up Hiero SDK Upstream
21+
run: |
22+
git remote set-url origin https://github.com/hiero-ledger/hiero-sdk-python.git
23+
24+
- name: Fetch main branch
25+
run: |
26+
git fetch origin main
27+
28+
- name: Check added test file names
29+
run: |
30+
chmod +x .github/scripts/check_test_files.sh
31+
.github/scripts/check_test_files.sh

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
5050
- Add new `.github/ISSUE_TEMPLATE/05_intermediate_issue.yml` file (1072)(https://github.com/hiero-ledger/hiero-sdk-python/issues/1072)
5151
- Add a workflow to notify the team when issues are labeled as “good first issues” or identified as candidates for that label: `bot-gfi-notify-team.yml`(#1115)
5252
- Added __str__ and __repr__ to AccountBalance
53+
- Added GitHub workflow that makes sure newly added test files follow pytest test files naming conventions (#1054)
5354

5455
### Changed
5556
- Move `account_allowance_delete_transaction_hbar.py` from `examples/` to `examples/account/` for better organization (#1003)

0 commit comments

Comments
 (0)