Skip to content

Commit f995713

Browse files
authored
Cleanup verdi tests (#6951)
* Various cleanups in verdi.sh tests - In 8.2.0, just running 'verdi' or 'python -m aiida' without any arguments returns non-zero code. In verdi.sh we add '-h' to workaround this. - Move verdi devel check-* commands to verdi.sh - Reduce verdi load limit to 300ms * Improve output of verdi devel commands
1 parent cfb7fd1 commit f995713

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

.github/workflows/ci-code.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ jobs:
129129
extras: ''
130130

131131
- name: Run verdi tests
132-
run: |
133-
verdi devel check-load-time
134-
verdi devel check-undesired-imports
135-
.github/workflows/verdi.sh
132+
run: .github/workflows/verdi.sh
136133

137134

138135
test-pytest-fixtures:

.github/workflows/verdi.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
5+
verdi devel check-load-time
6+
verdi devel check-undesired-imports
7+
38
# Test the loading time of `verdi`. This is an attempt to catch changes to the imports in `aiida.cmdline` that
49
# would slow down `verdi` invocations and make tab-completion unusable.
510
VERDI=`which verdi`
611

7-
# Typically, the loading time of `verdi` should be around ~0.2 seconds.
12+
# Typically, the loading time of `verdi` should be around <0.2 seconds.
813
# Typically these types of tests are fragile. But with a load limit of more than twice
914
# the ideal loading time, if exceeded, should give a reasonably sure indication
1015
# that the loading of `verdi` is unacceptably slowed down.
11-
LOAD_LIMIT=0.4
16+
LOAD_LIMIT=0.3
1217
MAX_NUMBER_ATTEMPTS=5
1318

1419
iteration=0
1520

1621
while true; do
1722

1823
iteration=$((iteration+1))
19-
load_time=$(/usr/bin/time -q -f "%e" $VERDI 2>&1 > /dev/null)
24+
load_time=$(/usr/bin/time -q -f "%e" $VERDI -h 2>&1 > /dev/null)
2025

2126
if (( $(echo "$load_time < $LOAD_LIMIT" | bc -l) )); then
2227
echo "SUCCESS: loading time $load_time at iteration $iteration below $LOAD_LIMIT"
@@ -36,15 +41,18 @@ done
3641

3742
# Test that we can also run the CLI via `python -m aiida`,
3843
# that it returns a 0 exit code, and contains the expected stdout.
39-
echo "Invoking verdi via `python -m aiida`"
40-
OUTPUT=$(python -m aiida 2>&1)
44+
echo "Invoking verdi via 'python -m aiida -h'"
45+
OUTPUT=$(python -m aiida -h 2>&1)
4146
RETVAL=$?
42-
echo $OUTPUT
4347
if [ $RETVAL -ne 0 ]; then
4448
echo "'python -m aiida' exitted with code $RETVAL"
49+
echo "=== OUTPUT ==="
50+
echo $OUTPUT
4551
exit 2
4652
fi
4753
if [[ $OUTPUT != *"command line interface of AiiDA"* ]]; then
4854
echo "'python -m aiida' did not contain the expected stdout:"
55+
echo "=== OUTPUT ==="
56+
echo $OUTPUT
4957
exit 2
5058
fi

src/aiida/cmdline/commands/cmd_devel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def devel_check_load_time():
5454
f'potential `verdi` speed problem: `{loaded}` module is imported which is not in: {allowed}'
5555
)
5656

57-
echo.echo_success('no issues detected')
57+
echo.echo_success('no load time issues detected')
5858

5959

6060
@verdi_devel.command('check-undesired-imports')
@@ -65,7 +65,7 @@ def devel_check_undesired_imports():
6565
"""
6666
loaded_modules = 0
6767

68-
unwanted_modules = [
68+
undesired_modules = [
6969
'requests',
7070
'plumpy',
7171
'disk_objectstore',
@@ -81,15 +81,15 @@ def devel_check_undesired_imports():
8181
# trogon powers the optional TUI and uses asyncio.
8282
# Check for asyncio only when the optional tui extras are not installed.
8383
if 'trogon' not in sys.modules:
84-
unwanted_modules += 'asyncio'
85-
for modulename in unwanted_modules:
84+
undesired_modules += 'asyncio'
85+
for modulename in undesired_modules:
8686
if modulename in sys.modules:
8787
echo.echo_warning(f'Detected loaded module "{modulename}"')
8888
loaded_modules += 1
8989

9090
if loaded_modules > 0:
91-
echo.echo_critical(f'Detected {loaded_modules} unwanted modules')
92-
echo.echo_success('no issues detected')
91+
echo.echo_critical(f'Detected {loaded_modules} undesired modules')
92+
echo.echo_success('no undesired modules detected')
9393

9494

9595
@verdi_devel.command('validate-plugins')

0 commit comments

Comments
 (0)