tests: replace pycodestyle with black
[vpp.git] / test / config.py
index dd3b9c1..c99d1ca 100644 (file)
@@ -12,6 +12,7 @@ def positive_int_or_default(default):
         if int(v) <= 0:
             raise ValueError("value must be positive")
         return int(v)
+
     return positive_integer
 
 
@@ -22,6 +23,7 @@ def positive_float_or_default(default):
         if float(v) <= 0:
             raise ValueError("value must be positive")
         return float(v)
+
     return positive_float
 
 
@@ -50,6 +52,7 @@ def int_choice_or_default(options, default):
         if int(v) in options:
             return int(v)
         raise ValueError("invalid choice")
+
     return choice
 
 
@@ -57,14 +60,13 @@ def worker_config(v):
     if v is None or v == "":
         return 0
     if v.startswith("workers "):
-        return(int(v.split(" ")[1]))
+        return int(v.split(" ")[1])
     return int(v)
 
 
 def directory(v):
     if not os.path.isdir(v):
-        raise ValueError(f"provided path '{v}' doesn't exist "
-                         "or is not a directory")
+        raise ValueError(f"provided path '{v}' doesn't exist or is not a directory")
     return v
 
 
@@ -74,35 +76,51 @@ def directory_verify_or_create(v):
     return v
 
 
-parser = argparse.ArgumentParser(description="VPP unit tests",
-                                 formatter_class=argparse.RawTextHelpFormatter)
+parser = argparse.ArgumentParser(
+    description="VPP unit tests", formatter_class=argparse.RawTextHelpFormatter
+)
 
-parser.add_argument("--failfast", action="store_true",
-                    help="stop running tests on first failure")
+parser.add_argument(
+    "--failfast", action="store_true", help="stop running tests on first failure"
+)
 
-parser.add_argument("--test-src-dir", action="append", type=directory,
-                    help="directory containing test files "
-                    "(may be specified multiple times) "
-                    "(VPP_WS_DIR/test is added automatically to the set)")
+parser.add_argument(
+    "--test-src-dir",
+    action="append",
+    type=directory,
+    help="directory containing test files "
+    "(may be specified multiple times) "
+    "(VPP_WS_DIR/test is added automatically to the set)",
+)
 
 default_verbose = 0
 
-parser.add_argument("--verbose", action="store", default=default_verbose,
-                    type=int_choice_or_default((0, 1, 2), default_verbose),
-                    help="verbosity setting - 0 - least verbose, "
-                    "2 - most verbose (default: 0)")
+parser.add_argument(
+    "--verbose",
+    action="store",
+    default=default_verbose,
+    type=int_choice_or_default((0, 1, 2), default_verbose),
+    help="verbosity setting - 0 - least verbose, 2 - most verbose (default: 0)",
+)
 
 default_test_run_timeout = 600
 
-parser.add_argument("--timeout", action="store",
-                    type=positive_int_or_default(default_test_run_timeout),
-                    default=default_test_run_timeout,
-                    metavar="TEST_RUN_TIMEOUT",
-                    help="test run timeout in seconds - per test "
-                    f"(default: {default_test_run_timeout})")
-
-parser.add_argument("--failed-dir", action="store", type=directory,
-                    help="directory containing failed tests")
+parser.add_argument(
+    "--timeout",
+    action="store",
+    type=positive_int_or_default(default_test_run_timeout),
+    default=default_test_run_timeout,
+    metavar="TEST_RUN_TIMEOUT",
+    help="test run timeout in seconds - per test "
+    f"(default: {default_test_run_timeout})",
+)
+
+parser.add_argument(
+    "--failed-dir",
+    action="store",
+    type=directory,
+    help="directory containing failed tests",
+)
 
 filter_help_string = """\
 expression consists of 3 string selectors separated by '.' separators:
@@ -126,17 +144,23 @@ examples:
 4. '.*.test_add_bfd' selects all test functions named test_add_bfd
    from all files/classes
 """
-parser.add_argument("--filter", action="store",
-                    metavar="FILTER_EXPRESSION", help=filter_help_string)
+parser.add_argument(
+    "--filter", action="store", metavar="FILTER_EXPRESSION", help=filter_help_string
+)
 
 default_retries = 0
 
-parser.add_argument("--retries", action="store", default=default_retries,
-                    type=positive_int_or_default(default_retries),
-                    help="retry failed tests RETRIES times")
+parser.add_argument(
+    "--retries",
+    action="store",
+    default=default_retries,
+    type=positive_int_or_default(default_retries),
+    help="retry failed tests RETRIES times",
+)
 
-parser.add_argument("--step", action="store_true", default=False,
-                    help="enable stepping through tests")
+parser.add_argument(
+    "--step", action="store_true", default=False, help="enable stepping through tests"
+)
 
 debug_help_string = """\
 attach     - attach to already running vpp
@@ -145,80 +169,153 @@ gdb        - print VPP PID and pause allowing attaching gdb
 gdbserver  - same as above, but run gdb in gdbserver
 """
 
-parser.add_argument("--debug", action="store",
-                    choices=["attach", "core", "gdb", "gdbserver"],
-                    help=debug_help_string)
-
-parser.add_argument("--debug-framework", action="store_true",
-                    help="enable internal test framework debugging")
-
-parser.add_argument("--compress-core", action="store_true",
-                    help="compress core files if not debugging them")
-
-parser.add_argument("--extended", action="store_true",
-                    help="run extended tests")
-
-parser.add_argument("--sanity", action="store_true",
-                    help="perform sanity vpp run before running tests")
-
-parser.add_argument("--force-foreground", action="store_true",
-                    help="force running in foreground - don't fork")
-
-parser.add_argument("--jobs", action="store", type=positive_int_or_auto,
-                    default="auto", help="maximum concurrent test jobs")
-
-parser.add_argument("--venv-dir", action="store",
-                    type=directory, help="path to virtual environment")
+parser.add_argument(
+    "--debug",
+    action="store",
+    choices=["attach", "core", "gdb", "gdbserver"],
+    help=debug_help_string,
+)
+
+parser.add_argument(
+    "--debug-framework",
+    action="store_true",
+    help="enable internal test framework debugging",
+)
+
+parser.add_argument(
+    "--compress-core",
+    action="store_true",
+    help="compress core files if not debugging them",
+)
+
+parser.add_argument("--extended", action="store_true", help="run extended tests")
+
+parser.add_argument(
+    "--sanity", action="store_true", help="perform sanity vpp run before running tests"
+)
+
+parser.add_argument(
+    "--force-foreground",
+    action="store_true",
+    help="force running in foreground - don't fork",
+)
+
+parser.add_argument(
+    "--jobs",
+    action="store",
+    type=positive_int_or_auto,
+    default="auto",
+    help="maximum concurrent test jobs",
+)
+
+parser.add_argument(
+    "--venv-dir", action="store", type=directory, help="path to virtual environment"
+)
 
 default_rnd_seed = time.time()
-parser.add_argument("--rnd-seed", action="store", default=default_rnd_seed,
-                    type=positive_float_or_default(default_rnd_seed),
-                    help="random generator seed (default: current time)")
-
-parser.add_argument("--vpp-worker-count", action="store", type=worker_config,
-                    default=0, help="number of vpp workers")
-
-parser.add_argument("--gcov", action="store_true",
-                    default=False, help="running gcov tests")
-
-parser.add_argument("--cache-vpp-output", action="store_true", default=False,
-                    help="cache VPP stdout/stderr and log as one block "
-                    "after test finishes")
-
-parser.add_argument("--vpp-ws-dir", action="store", required=True,
-                    type=directory, help="vpp workspace directory")
-
-parser.add_argument("--vpp-tag", action="store", default="vpp_debug",
-                    metavar="VPP_TAG", required=True,
-                    help="vpp tag (e.g. vpp, vpp_debug, vpp_gcov)")
-
-parser.add_argument("--vpp", action="store", help="path to vpp binary "
-                    "(default: derive from VPP_WS_DIR and VPP_TAG)")
-
-parser.add_argument("--vpp-install-dir", type=directory,
-                    action="store", help="path to vpp install directory"
-                    "(default: derive from VPP_WS_DIR and VPP_TAG)")
-
-parser.add_argument("--vpp-build-dir", action="store", type=directory,
-                    help="vpp build directory"
-                    "(default: derive from VPP_WS_DIR and VPP_TAG)")
-
-parser.add_argument("--vpp-plugin-dir", action="append", type=directory,
-                    help="directory containing vpp plugins"
-                    "(default: derive from VPP_WS_DIR and VPP_TAG)")
-
-parser.add_argument("--vpp-test-plugin-dir", action="append", type=directory,
-                    help="directory containing vpp api test plugins"
-                    "(default: derive from VPP_WS_DIR and VPP_TAG)")
-
-parser.add_argument("--extern-plugin-dir", action="append", type=directory,
-                    default=[], help="directory containing external plugins")
-
-parser.add_argument("--coredump-size", action="store", default="unlimited",
-                    help="specify vpp coredump size")
-
-parser.add_argument("--max-vpp-cpus", action="store", type=int_or_auto,
-                    default=0, help="max cpus used by vpp")
+parser.add_argument(
+    "--rnd-seed",
+    action="store",
+    default=default_rnd_seed,
+    type=positive_float_or_default(default_rnd_seed),
+    help="random generator seed (default: current time)",
+)
+
+parser.add_argument(
+    "--vpp-worker-count",
+    action="store",
+    type=worker_config,
+    default=0,
+    help="number of vpp workers",
+)
+
+parser.add_argument(
+    "--gcov", action="store_true", default=False, help="running gcov tests"
+)
+
+parser.add_argument(
+    "--cache-vpp-output",
+    action="store_true",
+    default=False,
+    help="cache VPP stdout/stderr and log as one block after test finishes",
+)
+
+parser.add_argument(
+    "--vpp-ws-dir",
+    action="store",
+    required=True,
+    type=directory,
+    help="vpp workspace directory",
+)
+
+parser.add_argument(
+    "--vpp-tag",
+    action="store",
+    default="vpp_debug",
+    metavar="VPP_TAG",
+    required=True,
+    help="vpp tag (e.g. vpp, vpp_debug, vpp_gcov)",
+)
+
+parser.add_argument(
+    "--vpp",
+    action="store",
+    help="path to vpp binary (default: derive from VPP_WS_DIR and VPP_TAG)",
+)
+
+parser.add_argument(
+    "--vpp-install-dir",
+    type=directory,
+    action="store",
+    help="path to vpp install directory"
+    "(default: derive from VPP_WS_DIR and VPP_TAG)",
+)
+
+parser.add_argument(
+    "--vpp-build-dir",
+    action="store",
+    type=directory,
+    help="vpp build directory (default: derive from VPP_WS_DIR and VPP_TAG)",
+)
+
+parser.add_argument(
+    "--vpp-plugin-dir",
+    action="append",
+    type=directory,
+    help="directory containing vpp plugins"
+    "(default: derive from VPP_WS_DIR and VPP_TAG)",
+)
+
+parser.add_argument(
+    "--vpp-test-plugin-dir",
+    action="append",
+    type=directory,
+    help="directory containing vpp api test plugins"
+    "(default: derive from VPP_WS_DIR and VPP_TAG)",
+)
+
+parser.add_argument(
+    "--extern-plugin-dir",
+    action="append",
+    type=directory,
+    default=[],
+    help="directory containing external plugins",
+)
+
+parser.add_argument(
+    "--coredump-size",
+    action="store",
+    default="unlimited",
+    help="specify vpp coredump size",
+)
+
+parser.add_argument(
+    "--max-vpp-cpus",
+    action="store",
+    type=int_or_auto,
+    default=0,
+    help="max cpus used by vpp",
+)
 
 variant_help_string = """\
 specify which march node variant to unit test
@@ -228,26 +325,41 @@ specify which march node variant to unit test
 
 parser.add_argument("--variant", action="store", help=variant_help_string)
 
-parser.add_argument("--api-fuzz", action="store", default=None,
-                    help="specify api fuzzing parameters")
-
-parser.add_argument("--wipe-tmp-dir", action="store_true", default=True,
-                    help="remove test tmp directory before running test")
-
-parser.add_argument("--tmp-dir", action="store", default="/tmp",
-                    type=directory_verify_or_create,
-                    help="directory where to store test temporary directories")
-
-parser.add_argument("--log-dir", action="store",
-                    type=directory_verify_or_create,
-                    help="directory where to store directories "
-                    "containing log files (default: --tmp-dir)")
+parser.add_argument(
+    "--api-fuzz", action="store", default=None, help="specify api fuzzing parameters"
+)
+
+parser.add_argument(
+    "--wipe-tmp-dir",
+    action="store_true",
+    default=True,
+    help="remove test tmp directory before running test",
+)
+
+parser.add_argument(
+    "--tmp-dir",
+    action="store",
+    default="/tmp",
+    type=directory_verify_or_create,
+    help="directory where to store test temporary directories",
+)
+
+parser.add_argument(
+    "--log-dir",
+    action="store",
+    type=directory_verify_or_create,
+    help="directory where to store directories "
+    "containing log files (default: --tmp-dir)",
+)
 
 default_keep_pcaps = False
-parser.add_argument("--keep-pcaps", action="store_true",
-                    default=default_keep_pcaps,
-                    help="if set, keep all pcap files from a test run"
-                    f" (default: {default_keep_pcaps})")
+parser.add_argument(
+    "--keep-pcaps",
+    action="store_true",
+    default=default_keep_pcaps,
+    help="if set, keep all pcap files from a test run"
+    f" (default: {default_keep_pcaps})",
+)
 
 config = parser.parse_args()
 
@@ -268,12 +380,13 @@ libs = ["lib", "lib64"]
 
 if config.vpp_plugin_dir is None:
     config.vpp_plugin_dir = [
-        f"{config.vpp_install_dir}/vpp/{lib}/vpp_plugins" for lib in libs]
+        f"{config.vpp_install_dir}/vpp/{lib}/vpp_plugins" for lib in libs
+    ]
 
 if config.vpp_test_plugin_dir is None:
     config.vpp_test_plugin_dir = [
-        f"{config.vpp_install_dir}/vpp/{lib}/vpp_api_test_plugins"
-        for lib in libs]
+        f"{config.vpp_install_dir}/vpp/{lib}/vpp_api_test_plugins" for lib in libs
+    ]
 
 test_dirs = [f"{ws}/test"]
 
@@ -289,7 +402,7 @@ if config.venv_dir is None:
 available_cpus = psutil.Process().cpu_affinity()
 num_cpus = len(available_cpus)
 
-if config.max_vpp_cpus == 'auto':
+if config.max_vpp_cpus == "auto":
     max_vpp_cpus = num_cpus
 elif config.max_vpp_cpus > 0:
     max_vpp_cpus = min(config.max_vpp_cpus, num_cpus)