Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

unittests: test_kdoc_parser: add command line arg to read a YAML file

The test_kdoc_parser.py already supports loading dynamic tests
when running unit tests.

Add support to read from a different file. This is useful for:
- regression tests before/afer some changes;
- preparing new unit tests;
- test a different yaml before adding its contents at
tools/unittests/kdoc-test.yaml.

It should be noticed that passing an argument to a unit test
is not too trivial, as unittest core will load itself the
runner with a separate environment. The best (only?) way to
do it is by setting the system environment. This way, when
the class is called by the unit test loader, it can pick
the var from the environment without relying on a global
variable.

The unittest_helper has already provision for it, so let's
use its support.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <1d1a56de012c43756f9ca87aa9bf6c285674f113.1774256269.git.mchehab+huawei@kernel.org>

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
3f049a5b 625ce45f

+20 -3
+20 -3
tools/unittests/test_kdoc_parser.py
··· 30 30 31 31 from kdoc.xforms_lists import CTransforms 32 32 33 - from unittest_helper import run_unittest 33 + from unittest_helper import TestUnits 34 34 35 35 36 36 # 37 37 # Test file 38 38 # 39 39 TEST_FILE = os.path.join(SRC_DIR, "kdoc-test.yaml") 40 + 41 + env = { 42 + "yaml_file": TEST_FILE 43 + } 40 44 41 45 # 42 46 # Ancillary logic to clean whitespaces ··· 474 470 optional ones. 475 471 """ 476 472 477 - with open(TEST_FILE, encoding="utf-8") as fp: 473 + test_file = os.environ.get("yaml_file", TEST_FILE) 474 + 475 + with open(test_file, encoding="utf-8") as fp: 478 476 testset = yaml.safe_load(fp) 479 477 480 478 tests = testset["tests"] ··· 537 531 # Run all tests 538 532 # 539 533 if __name__ == "__main__": 540 - run_unittest(__file__) 534 + runner = TestUnits() 535 + parser = runner.parse_args() 536 + parser.add_argument("-y", "--yaml-file", "--yaml", 537 + help='Name of the yaml file to load') 538 + 539 + args = parser.parse_args() 540 + 541 + if args.yaml_file: 542 + env["yaml_file"] = os.path.expanduser(args.yaml_file) 543 + 544 + # Run tests with customized arguments 545 + runner.run(__file__, parser=parser, args=args, env=env)