Skip to content

Commit

Permalink
Merge pull request #1747 from buildtesters/refactor_code_for_buildtes…
Browse files Browse the repository at this point in the history
…t_class

Refactor code BuildTest class
  • Loading branch information
shahzebsiddiqui authored Apr 8, 2024
2 parents b79dd92 + 78b2f7c commit c7bb34b
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 297 deletions.
3 changes: 0 additions & 3 deletions buildtest/buildsystem/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __init__(
filters,
testdir,
configuration,
buildtest_system,
rebuild=1,
numprocs=None,
numnodes=None,
Expand All @@ -46,7 +45,6 @@ def __init__(
filters (dict): List of filter fields specified via ``buildtest build --filter`` for filtering tests
testdir (str): Test directory where tests will be written which could be specified via ``buildtest build --testdir`` or configuration file
configuration (buildtest.config.SiteConfiguration): Instance of SiteConfiguration class
buildtest_system (buildtest.system.BuildTestSystem): Instance of BuildTestSystem class
rebuild (int, option): Number of rebuild for test. This is specified via ``buildtest build --rebuild``. Defaults to 1
numprocs (list, optional): List of processor values to create builder objects specified via ``buildtest build --procs``
numnodes (list, optional): List of processor values to create builder objects specified via ``buildtest build --nodes``
Expand All @@ -55,7 +53,6 @@ def __init__(
"""

self.configuration = configuration
self.system = buildtest_system
self.logger = logging.getLogger(__name__)
self.testdir = testdir
self.buildexecutor = buildexecutor
Expand Down
30 changes: 14 additions & 16 deletions buildtest/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
for building test scripts from a Buildspec
"""

import getpass
import json
import logging
import os
import platform
import re
import shutil
import sys
Expand Down Expand Up @@ -46,7 +48,6 @@
from buildtest.executors.setup import BuildExecutor
from buildtest.log import init_logfile
from buildtest.schemas.defaults import custom_validator, schema_table
from buildtest.system import BuildTestSystem
from buildtest.utils.file import (
create_dir,
is_dir,
Expand Down Expand Up @@ -606,7 +607,6 @@ def __init__(
dry_run=None,
filter_buildspecs=None,
rebuild=None,
buildtest_system=None,
report_file=None,
maxpendtime=None,
poll_interval=None,
Expand Down Expand Up @@ -645,7 +645,6 @@ def __init__(
dry_run (bool, optional): Show a list of tests that will potentially be run without actually running them via ``buildtest build --dry-run``
filter_buildspecs (dict, optional): filters buildspecs and tests based on ``buildtest build --filter`` argument which is a key/value dictionary that can filter tests based on **tags**, **type**, and **maintainers**
rebuild (int, optional): Rebuild tests X times based on ``buildtest build --rebuild`` option.
buildtest_system (buildtest.system.BuildTestSystem, optional): Instance of BuildTestSystem class
report_file (str, optional): Location to report file where test data will be written upon completion. This can be specified via ``buildtest build --report`` command
maxpendtime (int, optional): Specify maximum pending time in seconds for batch job until job is cancelled
poll_interval (int, optional): Specify poll interval in seconds for polling batch jobs.
Expand Down Expand Up @@ -819,24 +818,24 @@ def __init__(
timeout=self.timeout,
max_jobs=self.max_jobs,
)

"""
self.system = buildtest_system
if not isinstance(self.system, BuildTestSystem):
self.system = BuildTestSystem()

"""
if self.filter_buildspecs:
self._validate_filters()

msg = f"""
[magenta]User:[/] [cyan]{self.system.system['user']}
[magenta]Hostname:[/] [cyan]{self.system.system['host']}
[magenta]Platform:[/] [cyan]{self.system.system['platform']}
[magenta]User:[/] [cyan]{getpass.getuser()}
[magenta]Hostname:[/] [cyan]{platform.node()}
[magenta]Platform:[/] [cyan]{platform.system()}
[magenta]Current Time:[/] [cyan]{datetime.now().strftime('%Y/%m/%d %X')}
[magenta]buildtest path:[/] [cyan]{shutil.which('buildtest')}
[magenta]buildtest version:[/] [cyan]{BUILDTEST_VERSION}
[magenta]python path:[/] [cyan]{self.system.system['python']}
[magenta]python version:[/] [cyan]{self.system.system['pyver']}[/]
[magenta]python path:[/] [cyan]{os.getenv("BUILDTEST_PYTHON")}
[magenta]python version:[/] [cyan]{platform.python_version()}[/]
[magenta]Configuration File:[/] [cyan]{self.configuration.file}[/]
[magenta]Test Directory:[/] [cyan]{self.testdir}[/]
[magenta]Report File:[/] [cyan]{self.report_file}[/]
Expand Down Expand Up @@ -1183,7 +1182,6 @@ def parse_buildspecs(self):
filters=self.filter_buildspecs,
testdir=self.testdir,
rebuild=self.rebuild,
buildtest_system=self.system,
configuration=self.configuration,
numprocs=self.numprocs,
numnodes=self.numnodes,
Expand Down Expand Up @@ -1438,13 +1436,13 @@ def _update_build_history(self, builders):

history_data = {
"command": " ".join(sys.argv),
"user": self.system.system["user"],
"hostname": self.system.system["host"],
"platform": self.system.system["platform"],
"user": getpass.getuser(),
"hostname": platform.node(),
"platform": platform.system(),
"date": datetime.now().strftime("%Y/%m/%d %X"),
"buildtest": shutil.which("buildtest"),
"python": self.system.system["python"],
"python_version": self.system.system["pyver"],
"python": os.getenv("BUILDTEST_PYTHON"),
"python_version": platform.python_version(),
"testdir": self.testdir,
"configuration": self.configuration.file,
"system": self.configuration.name(),
Expand Down
1 change: 0 additions & 1 deletion buildtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def main():
validate=args.validate,
dry_run=args.dry_run,
testdir=args.testdir,
buildtest_system=system,
report_file=report_file,
maxpendtime=args.maxpendtime,
poll_interval=args.pollinterval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ system:
torque:
dev:
queue: development
options: [ "-l walltime 00:10:00" ]
options: ["-l walltime 00:10:00"]
container:
ubuntu:
image: ubuntu:20.04
Expand Down
73 changes: 16 additions & 57 deletions tests/builders/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,47 @@
def test_assert_ge():
"""This test buildspec using status check with 'assert_ge'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "assert_ge.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "assert_ge.yml")], configuration=config
)
cmd.build()


def test_assert_le():
"""This test buildspec using status check with 'assert_le'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "assert_le.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "assert_le.yml")], configuration=config
)
cmd.build()


def test_assert_gt():
"""This test buildspec using status check with 'assert_gt'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "assert_gt.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "assert_gt.yml")], configuration=config
)
cmd.build()


def test_assert_lt():
"""This test buildspec using status check with 'assert_lt'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "assert_lt.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "assert_lt.yml")], configuration=config
)
cmd.build()


def test_assert_eq():
"""This test buildspec using status check with 'assert_eq'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "assert_eq.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "assert_eq.yml")], configuration=config
)
cmd.build()


def test_assert_ne():
"""This test buildspec using status check with 'assert_ne'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "assert_ne.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "assert_ne.yml")], configuration=config
)
cmd.build()

Expand All @@ -82,9 +70,7 @@ def test_assert_contains():
"""This test buildspec using status check with 'assert_contains'"""

cmd = BuildTest(
buildspecs=[os.path.join(here, "contains.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "contains.yml")], configuration=config
)
cmd.build()

Expand All @@ -93,39 +79,29 @@ def test_assert_range():
"""This test buildspec using status check with 'assert_range'"""

cmd = BuildTest(
buildspecs=[os.path.join(here, "assert_range.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "assert_range.yml")], configuration=config
)
cmd.build()


def test_assert_is_symlink():
"""This test buildspec using status check with 'is_symlink'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "is_symlink.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "is_symlink.yml")], configuration=config
)
cmd.build()


def test_assert_exists():
"""This test buildspec using status check with 'exists'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "exists.yml")],
buildtest_system=system,
configuration=config,
)
cmd = BuildTest(buildspecs=[os.path.join(here, "exists.yml")], configuration=config)
cmd.build()


def test_assert_is_file_is_dir():
"""This test buildspec using status check with 'is_dir' and 'is_file'"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "file_and_dir_check.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "file_and_dir_check.yml")], configuration=config
)
cmd.build()

Expand All @@ -139,7 +115,6 @@ def test_file_count():
os.path.join(here, "file_count_filetype.yml"),
os.path.join(here, "file_count_file_traverse_limit.yml"),
],
buildtest_system=system,
configuration=config,
)
cmd.build()
Expand All @@ -148,19 +123,15 @@ def test_file_count():
def test_multicompilers_with_script_schema():
"""This test will run the stream benchmark with multiple compilers using the 'compilers' keyword in script schema"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "stream_example.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "stream_example.yml")], configuration=config
)
cmd.build()


def test_regex_check():
"""This test buildspec using status check with regex"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "status_regex.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "status_regex.yml")], configuration=config
)
cmd.build()

Expand All @@ -172,7 +143,6 @@ def test_file_regex():
os.path.join(here, "regex_on_filename.yml"),
os.path.join(here, "regex_on_invalids.yml"),
],
buildtest_system=system,
configuration=config,
)
cmd.build()
Expand All @@ -181,29 +151,23 @@ def test_file_regex():
def test_regex_type():
"""This test will perform status check with different regular expression type using ``re`` property that can be "re.match", "re.search", "re.fullmatch" """
cmd = BuildTest(
buildspecs=[os.path.join(here, "specify_regex_type.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "specify_regex_type.yml")], configuration=config
)
cmd.build()


def test_runtime_check():
"""This test will perform status check with runtime"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "runtime_status_test.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "runtime_status_test.yml")], configuration=config
)
cmd.build()


def test_linecount():
"""This test will perform status check with linecount"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "linecount.yml")],
buildtest_system=system,
configuration=config,
buildspecs=[os.path.join(here, "linecount.yml")], configuration=config
)
cmd.build()

Expand All @@ -215,14 +179,12 @@ def test_file_linecount():
os.path.join(here, "file_linecount.yml"),
os.path.join(here, "file_linecount_failure.yml"),
],
buildtest_system=system,
configuration=config,
)
cmd.build()

cmd = BuildTest(
buildspecs=[os.path.join(here, "file_linecount_invalid.yml")],
buildtest_system=system,
configuration=config,
)
with pytest.raises(SystemExit):
Expand All @@ -233,7 +195,6 @@ def test_metrics_with_regex_type():
"""This test will perform status check with regular expression type and metrics"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "metrics_with_regex_type.yml")],
buildtest_system=system,
configuration=config,
)
cmd.build()
Expand All @@ -243,7 +204,6 @@ def test_metrics_regex_with_linenum():
"""This test will perform status check on a particular line where regular expression is applied"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "metrics_regex_with_linenum.yml")],
buildtest_system=system,
configuration=config,
)
cmd.build()
Expand All @@ -253,7 +213,6 @@ def test_metrics_regex_with_invalid_linenum():
"""This test will test metrics regex with invalid line number"""
cmd = BuildTest(
buildspecs=[os.path.join(here, "metrics_regex_with_invalid_linenum.yml")],
buildtest_system=system,
configuration=config,
)
cmd.build()
2 changes: 0 additions & 2 deletions tests/builders/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def test_docker_example():
buildspecs=[
os.path.join(BUILDTEST_ROOT, "tutorials", "containers", "hello_world.yml")
],
buildtest_system=system,
configuration=config,
)
cmd.build()
Expand All @@ -40,7 +39,6 @@ def test_singularity_example():
BUILDTEST_ROOT, "tutorials", "containers", "hello_world_singularity.yml"
)
],
buildtest_system=system,
configuration=config,
)
cmd.build()
Loading

0 comments on commit c7bb34b

Please sign in to comment.