Skip to content

Commit fde5bb4

Browse files
author
Alan Christie
committed
Now supports run-level
1 parent 104cb6f commit fde5bb4

File tree

2 files changed

+61
-23
lines changed

2 files changed

+61
-23
lines changed

README.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ it must *exist* and contain ``100`` lines::
4242
checks:
4343
- exists: true
4444
- lineCount: 100
45-
Individual tests can be prevented from being processed by adding an `ignore`
45+
Individual tests can be prevented from being executed by adding an `ignore`
4646
declaration::
4747

4848
jobs:
@@ -54,6 +54,23 @@ declaration::
5454
ignore:
5555
[...]
5656

57+
Tests can be assigned a ``run-level``. Run-levels are numerical value (1..100)
58+
that can be used to classify your tests, often using it to represent
59+
execution time. By default all tests that have no run-level and those with
60+
run-level ``1`` are executed. You can set the run-level for longer-running
61+
tests higher value, e.g. ``10``. To run these more time-consuming tests you
62+
specify the new run-level when running jote: ``jote --run-level 10``.
63+
64+
You define the run-level in the root block of the job specification::
65+
66+
jobs:
67+
[...]
68+
max-min-picker:
69+
[...]
70+
tests:
71+
simple-execution:
72+
run-level: 5
73+
[...]
5774

5875
Installation
5976
------------

jote/jote.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,16 @@ def _check(t_compose: Compose,
291291
def _test(args: argparse.Namespace,
292292
collection: str,
293293
job: str,
294-
job_definition: DefaultMunch) -> Tuple[int, int, int]:
295-
"""Runs the tests for a specific Job definition returning True on success.
296-
If an individual test is marked as 'ignored' it will not be processed,
297-
and will not be counted.
298-
299-
The function returns a tuple containing the count of the number of tests
300-
that passed, were ignored and those that failed.
294+
job_definition: DefaultMunch) -> Tuple[int, int, int, int]:
295+
"""Runs the tests for a specific Job definition returning the number
296+
of tests passed, skipped (due to run-level), ignored and failed.
301297
"""
302298
assert job_definition
303299
assert isinstance(job_definition, DefaultMunch)
304300

305301
# The test status, assume success
306302
tests_passed: int = 0
303+
tests_skipped: int = 0
307304
tests_ignored: int = 0
308305
tests_failed: int = 0
309306

@@ -337,6 +334,15 @@ def _test(args: argparse.Namespace,
337334
tests_ignored += 1
338335
continue
339336

337+
# Does the test have a 'run-level' declaration?
338+
# If so, is it higher than the run-level specified?
339+
if 'run-level' in job_definition.tests[job_test_name]:
340+
run_level: int = job_definition.tests[job_test_name]['run-level']
341+
if run_level > args.run_level:
342+
print(f'W Skipping test (test is "run-level: {run_level}")')
343+
tests_skipped += 1
344+
continue
345+
340346
# Render the command for this test.
341347

342348
# First extract the variables and values from 'options'
@@ -510,7 +516,7 @@ def _test(args: argparse.Namespace,
510516
if not test_status and args.exit_on_failure:
511517
break
512518

513-
return tests_passed, tests_ignored, tests_failed
519+
return tests_passed, tests_skipped, tests_ignored, tests_failed
514520

515521

516522
def _wipe() -> None:
@@ -521,6 +527,17 @@ def _wipe() -> None:
521527
shutil.rmtree(test_root)
522528

523529

530+
def arg_check_run_level(value: str) -> int:
531+
"""A type checker for the argparse run-level.
532+
"""
533+
i_value = int(value)
534+
if i_value < 1:
535+
raise argparse.ArgumentTypeError('Minimum value is 1')
536+
if i_value > 100:
537+
raise argparse.ArgumentTypeError('Maximum value is 100')
538+
return i_value
539+
540+
524541
# -----------------------------------------------------------------------------
525542
# main
526543
# -----------------------------------------------------------------------------
@@ -553,6 +570,12 @@ def main() -> int:
553570
' is required. If not specified all the Tests'
554571
' that match the collection will be'
555572
' candidates for testing.')
573+
arg_parser.add_argument('-r', '--run-level',
574+
help='The run-level of the tests you want to'
575+
' execute. All tests at or below this level'
576+
' will be executed, a value from 1 to 100',
577+
default=1,
578+
type=arg_check_run_level)
556579

557580
arg_parser.add_argument('-d', '--dry-run', action='store_true',
558581
help='Setting this flag will result in jote'
@@ -606,8 +629,9 @@ def main() -> int:
606629
arg_parser.error('Cannot use --wipe and --keep-results')
607630

608631
# Args are OK if we get here.
609-
total_fail_count: int = 0
632+
total_skipped_count: int = 0
610633
total_ignore_count: int = 0
634+
total_fail_count: int = 0
611635

612636
# Check CWD
613637
if not _check_cwd():
@@ -657,11 +681,12 @@ def main() -> int:
657681
continue
658682

659683
if job_definition.jobs[job_name].tests:
660-
_, num_ignored, num_failed =\
684+
_, num_skipped, num_ignored, num_failed =\
661685
_test(args,
662686
collection,
663687
job_name,
664688
job_definition.jobs[job_name])
689+
total_skipped_count += num_skipped
665690
total_ignore_count += num_ignored
666691
total_fail_count += num_failed
667692

@@ -678,22 +703,18 @@ def main() -> int:
678703
print(' ---')
679704
total_pass_count: int = num_tests - total_fail_count - total_ignore_count
680705
dry_run: str = '[DRY RUN]' if args.dry_run else ''
706+
summary: str = f'passed={total_pass_count}' \
707+
f' skipped={total_skipped_count}' \
708+
f' ignored={total_ignore_count}'
681709
if total_fail_count:
682-
arg_parser.error('Done (FAILURE)'
683-
f' passed={total_pass_count}'
684-
f' ignored={total_ignore_count}'
685-
f' failed={total_fail_count}'
710+
arg_parser.error(f'Done (FAILURE) {summary} failed={total_fail_count}'
686711
f' {dry_run}')
687712
elif total_pass_count == 0 and not args.allow_no_tests:
688-
arg_parser.error('Done (FAILURE)'
689-
f' passed={total_pass_count}'
690-
f' ignored={total_ignore_count}'
691-
f' failed=0'
692-
f' (at least one test must pass) {dry_run}')
713+
arg_parser.error(f'Done (FAILURE) {summary}'
714+
f' failed=0 (at least one test must pass)'
715+
f' {dry_run}')
693716
else:
694-
print(f'Done (OK)'
695-
f' passed={total_pass_count}'
696-
f' ignored={total_ignore_count} {dry_run}')
717+
print(f'Done (OK) {summary} {dry_run}')
697718

698719
# Automatically wipe.
699720
# If there have been no failures

0 commit comments

Comments
 (0)