From 5b7606371b09cdbd949acac6b016b201ef1e614f Mon Sep 17 00:00:00 2001 From: Marius Smytzek Date: Tue, 25 Jul 2023 11:09:14 +0200 Subject: [PATCH] updated versions --- requirements.txt | 7 +++-- requirements_test.txt | 7 +++-- setup.cfg | 8 +++--- src/sflkit/language/python/visitor.py | 10 +++++-- src/sflkit/runners/run.py | 39 +++++++++++++++++---------- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/requirements.txt b/requirements.txt index 80e0a2d..a4387c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ sflkitlib>=0.0.1 astor>=0.8.1 -numpy==1.25.1 -matplotlib==3.7.2 +numpy>=1.25.1 +matplotlib>=3.7.2 sortedcollections>=2.1.0 -parameterized>=0.8.1 -future>=0.18.3 \ No newline at end of file +parameterized>=0.8.1 \ No newline at end of file diff --git a/requirements_test.txt b/requirements_test.txt index 5d514ee..757835c 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,11 +1,10 @@ sflkitlib>=0.0.1 astor>=0.8.1 -numpy==1.25.1 -matplotlib==3.7.2 +numpy>=1.25.1 +matplotlib>=3.7.2 sortedcollections>=2.1.0 pytest>=7.2.2 pytest-cov>=4.1.0 pytest-html>=3.2.0 pytest-rerunfailures>=11.1.2 -parameterized>=0.8.1 -future>=0.18.3 \ No newline at end of file +parameterized>=0.8.1 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 8891f5b..8aae9e4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,8 +26,8 @@ python_requires = >=3.10 install_requires = sflkitlib>=0.0.1 astor>=0.8.1 - numpy==1.25.1 - matplotlib==3.7.2 + numpy>=1.25.1 + matplotlib>=3.7.2 sortedcollections>=2.1.0 parameterized>=0.8.1 @@ -38,8 +38,8 @@ where = src test = sflkitlib>=0.0.1 astor>=0.8.1 - numpy==1.25.1 - matplotlib==3.7.2 + numpy>=1.25.1 + matplotlib>=3.7.2 sortedcollections>=2.1.0 pytest>=7.2.2 pytest-cov>=4.1.0 diff --git a/src/sflkit/language/python/visitor.py b/src/sflkit/language/python/visitor.py index 9abaaa1..9410d30 100644 --- a/src/sflkit/language/python/visitor.py +++ b/src/sflkit/language/python/visitor.py @@ -74,6 +74,12 @@ def __create_node(self, injection: Injection, node: AST, body=False, doc=None): ) if injection.error: error_var = self.meta_visitor.tmp_generator.get_var_name() + raise_stmt = [ + Raise( + exc=Name(id=error_var), + cause=None, + ) + ] if body: node.body = ( Try( @@ -84,7 +90,7 @@ def __create_node(self, injection: Injection, node: AST, body=False, doc=None): id="BaseException", ), name=error_var, - body=injection.error, + body=injection.error + raise_stmt, ) ], orelse=[], @@ -101,7 +107,7 @@ def __create_node(self, injection: Injection, node: AST, body=False, doc=None): id="BaseException", ), name=error_var, - body=injection.error, + body=injection.error + raise_stmt, ) ], orelse=[], diff --git a/src/sflkit/runners/run.py b/src/sflkit/runners/run.py index 20b368e..ab1415a 100644 --- a/src/sflkit/runners/run.py +++ b/src/sflkit/runners/run.py @@ -16,6 +16,8 @@ rb"= ((((?P\d+) failed)|((?P

\d+) passed)|(\d+ warnings?))(, )?)+ in " ) +DEFAULT_TIMEOUT = 10 + class PytestNode(abc.ABC): def __init__(self, name: str, parent=None): @@ -141,7 +143,8 @@ def get_dir(self): class Runner(abc.ABC): - def __init__(self, re_filter: str = r".*"): + def __init__(self, re_filter: str = r".*", timeout=DEFAULT_TIMEOUT): + self.timeout = timeout self.re_filter = re.compile(re_filter) def get_tests(self, directory: Path, environ: Environment = None) -> List[str]: @@ -218,12 +221,16 @@ def __get_pytest_result__( def run_test( self, directory: Path, test: str, environ: Environment = None ) -> TestResult: - output = subprocess.run( - ["python", "-m", "pytest", test], - stdout=subprocess.PIPE, - env=environ, - cwd=directory, - ).stdout + try: + output = subprocess.run( + ["python", "-m", "pytest", test], + stdout=subprocess.PIPE, + env=environ, + cwd=directory, + timeout=self.timeout, + ).stdout + except subprocess.TimeoutExpired: + return TestResult.UNDEFINED successful, passing, failing = self.__get_pytest_result__(output) if successful: if passing > 0 and failing == 0: @@ -272,13 +279,17 @@ def run_test( else: test = self.failing[test_name] result = TestResult.FAILING - process = subprocess.run( - ["python", self.access] + test, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env=environ, - cwd=directory, - ) + try: + process = subprocess.run( + ["python", self.access] + test, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=environ, + cwd=directory, + timeout=self.timeout, + ) + except subprocess.TimeoutExpired: + return TestResult.UNDEFINED self.output[test_name] = ( process.stdout.decode("utf8"), process.stderr.decode("utf8"),