Changeset 5f0e94b in mod_gnutls for test/runtest.py


Ignore:
Timestamp:
Nov 29, 2020, 5:08:41 AM (2 years ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
master
Children:
663f975
Parents:
9231a4d
Message:

Use pathlib instead of os.path

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/runtest.py

    r9231a4d r5f0e94b  
    2020import itertools
    2121import os
    22 import os.path
    2322import subprocess
    2423import sys
    2524import tempfile
    2625import yaml
     26from pathlib import Path
    2727from unittest import SkipTest
    2828
     
    4141
    4242    """
    43     with os.scandir(dir) as it:
    44         found = None
    45         for entry in it:
    46             if entry.is_dir():
    47                 num = int(entry.name.split('_', maxsplit=1)[0])
    48                 if number == num:
    49                     if found:
    50                         # duplicate numbers are an error
    51                         raise LookupError('Multiple directories found for '
    52                                           f'test number {number}: '
    53                                           f'{found.name} and {entry.name}')
    54                     else:
    55                         found = entry
    56         if found is None:
    57             raise LookupError('No test directory found for test number '
    58                               f'{number}!')
    59         else:
    60             return (found.path, found.name)
     43    found = None
     44    for entry in dir.iterdir():
     45        if entry.is_dir():
     46            num = int(entry.name.split('_', maxsplit=1)[0])
     47            if number == num:
     48                if found:
     49                    # duplicate numbers are an error
     50                    raise LookupError('Multiple directories found for '
     51                                      f'test number {number}: '
     52                                      f'{found.name} and {entry.name}')
     53                else:
     54                    found = entry
     55    if found is None:
     56        raise LookupError('No test directory found for test number '
     57                          f'{number}!')
     58    return found, found.name
    6159
    6260
     
    9290    # The Automake environment always provides srcdir, the default is
    9391    # for manual use.
    94     srcdir = os.path.realpath(os.environ.get('srcdir', '.'))
     92    srcdir = Path(os.environ.get('srcdir', '.')).resolve()
    9593    # ensure environment srcdir is absolute
    96     os.environ['srcdir'] = srcdir
     94    os.environ['srcdir'] = str(srcdir)
    9795
    9896    # Find the configuration directory for the test in
    9997    # ${srcdir}/tests/, based on the test number.
    100     testdir, testname = find_testdir(args.test_number,
    101                                      os.path.join(srcdir, 'tests'))
     98    testdir, testname = find_testdir(args.test_number, srcdir / 'tests')
    10299    print(f'Found test {testname}, test dir is {testdir}')
    103100    os.environ['TEST_NAME'] = testname
     
    105102    # Load test config
    106103    try:
    107         with open(os.path.join(testdir, 'test.yaml'), 'r') as conf_file:
     104        with open(testdir / 'test.yaml', 'r') as conf_file:
    108105            test_conf = yaml.load(conf_file, Loader=yaml.Loader)
    109106    except FileNotFoundError:
     
    111108
    112109    # Load test case hooks (if any)
    113     plugin_path = os.path.join(testdir, 'hooks.py')
    114     plugin = mgstest.hooks.load_hooks_plugin(plugin_path)
     110    plugin = mgstest.hooks.load_hooks_plugin(testdir / 'hooks.py')
    115111
    116112    # PID file name varies depending on whether we're using
     
    124120    valgrind_log = None
    125121    if args.valgrind:
    126         valgrind_log = os.path.join('logs', f'valgrind-{testname}.log')
     122        valgrind_log = Path('logs', f'valgrind-{testname}.log')
    127123
    128124    # Define the available services
    129     apache = ApacheService(config=os.path.join(testdir, 'apache.conf'),
     125    apache = ApacheService(config=testdir / 'apache.conf',
    130126                           pidfile=f'apache2{pidaffix}.pid',
    131127                           valgrind_log=valgrind_log,
    132128                           valgrind_suppress=args.valgrind_suppressions)
    133     backend = ApacheService(config=os.path.join(testdir, 'backend.conf'),
     129    backend = ApacheService(config=testdir / 'backend.conf',
    134130                            pidfile=f'backend{pidaffix}.pid')
    135     ocsp = ApacheService(config=os.path.join(testdir, 'ocsp.conf'),
     131    ocsp = ApacheService(config=testdir / 'ocsp.conf',
    136132                         pidfile=f'ocsp{pidaffix}.pid',
    137133                         check=check_ocsp_responder)
     
    183179        await service_stack.enter_async_context(apache.run())
    184180        failed = await apache.wait_ready()
    185         if os.path.exists(os.path.join(testdir, 'fail.server')):
     181        if (testdir / 'fail.server').is_file():
    186182            if failed:
    187183                print('Apache server failed to start as expected',
Note: See TracChangeset for help on using the changeset viewer.