Skip to content

Commit 27c7801

Browse files
authored
Merge pull request #42 from exploreriii/test-2-test-workflow
ci: test testing workflow
2 parents a13fc0b + 4840738 commit 27c7801

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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")
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+
for exception in "${EXCEPTION_NAMES[@]}"; do
28+
if [[ $(basename "$filename") == "$exception" ]]; then
29+
return 0
30+
fi
31+
done
32+
if [[ $(basename "$filename") != *_test.py ]]; then
33+
ERRORS+=("${RED}ERROR${RESET}: Test file '$filename' doesn't end with '_test'. ${YELLOW}It has to follow the pytest naming convention.")
34+
return 1
35+
fi
36+
fi
37+
return 0
38+
}
39+
40+
while IFS=$'\t' read -r status file1 file2; do
41+
case "$status" in
42+
A) check_test_file_name "$file1" ;;
43+
R*) check_test_file_name "$file2" ;;
44+
C*) check_test_file_name "$file2" ;;
45+
esac
46+
done <<< "$DIFF_FILES"
47+
48+
if (( ${#ERRORS[@]} > 0 )); then
49+
for err in "${ERRORS[@]}"; do
50+
echo -e "$err"
51+
done
52+
exit 1
53+
fi
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test Files Naming Check
2+
3+
on:
4+
push
5+
6+
concurrency:
7+
group: pr-checks-${{ github.workflow }}-${{ github.ref || github.run_id }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
check-test-files:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
17+
18+
- name: Fetch main branch
19+
run: |
20+
git fetch origin main
21+
22+
- name: Check added test file names
23+
run: |
24+
chmod +x .github/scripts/check_test_files.sh
25+
.github/scripts/check_test_files.sh

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
4848
- Added Issue Reminder (no-PR) bot, .github/scripts/issue_reminder_no_pr.sh and .github/workflows/bot-issue-reminder-no-pr.yml to automatically detect assigned issues with no linked pull requests for 7+ days and post a gentle ReminderBot comment.(#951)
4949
- Add new `.github/ISSUE_TEMPLATE/05_intermediate_issue.yml` file (1072)(https://github.com/hiero-ledger/hiero-sdk-python/issues/1072)
5050
- 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)
51+
- Added github workflow that makes sure newly added test files follow pytest test files naming conventions (#1054)
5152

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

0 commit comments

Comments
 (0)