Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions hstest/common/reflection_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def str_to_stacktrace(str_trace: str) -> str:
File "C:\Users\**\JetBrains\**\plugins\python\helpers\pydev\pydevd.py", line 1477, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\**\JetBrains\**\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
exec(compile(contents+"\n", file, 'exec'), glob, loc)

Which will appear when testing locally inside PyCharm.
""" # noqa: W291, E501
""" # noqa: E501
if f"{os.sep}JetBrains{os.sep}" in trace:
continue

Expand Down
3 changes: 1 addition & 2 deletions hstest/dynamic/input/dynamic_input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def _eject_next_input(self) -> None:

new_input = clean_text(new_input)

if new_input.endswith("\n"):
new_input = new_input[:-1]
new_input = new_input.removesuffix("\n")

self._input_lines += new_input.split("\n")
2 changes: 0 additions & 2 deletions hstest/dynamic/output/output_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def print(obj) -> None:
if group:
OutputHandler.get_real_out().write(full)
OutputHandler.get_real_out().flush()
else:
pass

@staticmethod
def get_real_out() -> io.TextIOWrapper:
Expand Down
3 changes: 1 addition & 2 deletions hstest/stage/django_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def read_page(self, link: str) -> str:
return clean_text(urlopen(link).read().decode())

def get_url(self, link: str = "") -> str:
if link.startswith("/"):
link = link[1:]
link = link.removeprefix("/")
return f"http://localhost:{self.attach.port}/{link}"

def get(self, link: str) -> str:
Expand Down
3 changes: 1 addition & 2 deletions hstest/stage/flask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def __init__(self, args="", *, source: str = "") -> None:
self.attach.sources += [item]

def get_url(self, link: str = "", *, source: str | None = None):
if link.startswith("/"):
link = link[1:]
link = link.removeprefix("/")

def create_url(port: int) -> str:
return f"http://localhost:{port}/{link}"
Expand Down
15 changes: 8 additions & 7 deletions hstest/testing/execution/process_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ def __handle_process(self, *args: str) -> None:
OutputHandler.print(f"Handle process - written to stdin: {next_input!r}")
except ExitException:
OutputHandler.print("Handle process - EXIT EXCEPTION, stop input")
if self._wait_if_terminated():
if type(StageTest.curr_test_run.error_in_test) == OutOfInputError:
StageTest.curr_test_run.set_error_in_test(None)
OutputHandler.print(
"Handle process - Abort stopping input, everything is OK"
)
break
if self._wait_if_terminated() and (
type(StageTest.curr_test_run.error_in_test) == OutOfInputError
):
StageTest.curr_test_run.set_error_in_test(None)
OutputHandler.print(
"Handle process - Abort stopping input, everything is OK"
)
break
self.stop_input()
except BaseException as ex:
OutputHandler.print(f"Handle process - SOME EXCEPTION {ex}")
Expand Down
10 changes: 7 additions & 3 deletions hstest/testing/execution/searcher/base_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def _search_non_cached(

candidates = set(files)

for curr_filter in initial_filter, pre_main_filter, main_filter, post_main_filter:
for curr_filter in (
initial_filter,
pre_main_filter,
main_filter,
post_main_filter,
):
curr_filter.init_filter(folder, contents)

filtered_files: set[File] = {
Expand Down Expand Up @@ -253,8 +258,7 @@ def _parse_source(self, source: str) -> tuple[Folder, File, Module]:
source_module = source[: -len(ext)].replace(os.sep, ".")

elif os.sep in source:
if source.endswith(os.sep):
source = source[: -len(os.sep)]
source = source.removesuffix(os.sep)

source_folder = source
source_file = None
Expand Down
5 changes: 4 additions & 1 deletion hstest/testing/execution/searcher/cpp_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def search(self, where: str | None = None) -> RunnableFile:
return self._search(
where,
force_content_filters=[
MainFilter("int main()", source=lambda s: main_func_searcher.search(s) is not None),
MainFilter(
"int main()",
source=lambda s: main_func_searcher.search(s) is not None,
),
],
)
8 changes: 6 additions & 2 deletions hstest/testing/execution/searcher/go_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ def search(self, where: str | None = None) -> RunnableFile:
return self._search(
where,
force_content_filters=[
MainFilter("package main", source=lambda s: package_searcher.search(s) is not None),
MainFilter(
"func main()", source=lambda s: main_func_searcher.search(s) is not None
"package main",
source=lambda s: package_searcher.search(s) is not None,
),
MainFilter(
"func main()",
source=lambda s: main_func_searcher.search(s) is not None,
),
],
)
3 changes: 2 additions & 1 deletion hstest/testing/execution/searcher/python_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def init_regexes(_: Folder, sources: Sources) -> None:
file_filter=file_filter,
pre_main_filter=FileFilter(init_files=init_regexes, file=lambda f: not is_imported[f]),
main_filter=MainFilter(
"if __name__ == '__main__'", source=lambda s: "__name__" in s and "__main__" in s
"if __name__ == '__main__'",
source=lambda s: "__name__" in s and "__main__" in s,
),
)

Expand Down
6 changes: 5 additions & 1 deletion hstest/testing/plotting/drawing/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

class Drawing:
def __init__(
self, library: str, plot_type: str, data: DrawingData | None, kwargs: dict[str, Any]
self,
library: str,
plot_type: str,
data: DrawingData | None,
kwargs: dict[str, Any],
) -> None:
self.library: str = library
self.type: str = plot_type
Expand Down
11 changes: 7 additions & 4 deletions hstest/testing/plotting/matplotlib_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ def bar(x, height, *args, data=None, **kw):
height = np.full((len(x),), height)

drawings.append(
Drawing(DrawingLibrary.matplotlib, DrawingType.bar, DrawingData(x, height), kw)
Drawing(
DrawingLibrary.matplotlib,
DrawingType.bar,
DrawingData(x, height),
kw,
)
)
return None

Expand Down Expand Up @@ -171,9 +176,7 @@ def violinplot(dataset, *, data=None, **kwargs) -> None:
drawings.append(drawing)

def imshow(x, **kwargs) -> None:
curr_data = { # noqa: F841
"x": np.array(x, dtype=object)
}
curr_data = {"x": np.array(x, dtype=object)} # noqa: F841

drawing = Drawing(
DrawingLibrary.matplotlib,
Expand Down
45 changes: 33 additions & 12 deletions hstest/testing/plotting/pandas_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def get_line_drawings_with_normalized_data(data, x, y):
)
return drawings

for column in data.columns:
drawings.append(
DrawingBuilder.get_line_drawing(data.index, data[column], DrawingLibrary.pandas, {})
)
drawings.extend(
DrawingBuilder.get_line_drawing(data.index, data[column], DrawingLibrary.pandas, {})
for column in data.columns
)

return drawings

Expand Down Expand Up @@ -145,7 +145,10 @@ def get_box_drawings_with_normalized_data(data: pd.DataFrame, x, y):
if not is_numeric_dtype(data[column]):
continue

curr_data = {"x": np.array([column], dtype=object), "y": data[column].to_numpy()}
curr_data = {
"x": np.array([column], dtype=object),
"y": data[column].to_numpy(),
}

drawing = Drawing(DrawingLibrary.pandas, DrawingType.box, None, {})
drawings.append(drawing)
Expand Down Expand Up @@ -195,9 +198,7 @@ def get_dis_drawings_with_normalized_data(data, x, y):
if not is_numeric_dtype(data[column]):
continue

curr_data = { # noqa: F841
"x": data[column].to_numpy()
}
curr_data = {"x": data[column].to_numpy()} # noqa: F841

drawing = Drawing(DrawingLibrary.pandas, DrawingType.dis, None, {})
drawings.append(drawing)
Expand Down Expand Up @@ -344,24 +345,44 @@ def bar(data, x=None, y=None, **kw):
if type(y) == str:
y = [y]
for col in y:
bar(None, data[x].array.to_numpy(), data[col].array.to_numpy(), **kw)
bar(
None,
data[x].array.to_numpy(),
data[col].array.to_numpy(),
**kw,
)
return None

if x is not None:
for col in data.columns:
if col != x:
bar(None, data[x].array.to_numpy(), data[col].array.to_numpy(), **kw)
bar(
None,
data[x].array.to_numpy(),
data[col].array.to_numpy(),
**kw,
)
return None

if y is not None:
if type(y) == str:
y = [y]
for col in y:
bar(None, data[col].index.to_numpy(), data[col].array.to_numpy(), **kw)
bar(
None,
data[col].index.to_numpy(),
data[col].array.to_numpy(),
**kw,
)
return None

for col in data.columns:
bar(None, data[col].index.to_numpy(), data[col].array.to_numpy(), **kw)
bar(
None,
data[col].index.to_numpy(),
data[col].array.to_numpy(),
**kw,
)
return None

if type(data) == pandas.Series:
Expand Down
25 changes: 17 additions & 8 deletions hstest/testing/plotting/seaborn_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ def replace_plots(drawings: DrawingsStorage) -> None:
return

def displot(data=None, **kwargs) -> None:
x = kwargs.get("x", None)
y = kwargs.get("y", None)
x = kwargs.get("x")
y = kwargs.get("y")

if data is None:
curr_data = {"x": np.array(x, dtype=object), "y": np.array(y, dtype=object)}
curr_data = {
"x": np.array(x, dtype=object),
"y": np.array(y, dtype=object),
}

drawing = Drawing(
DrawingLibrary.seaborn,
Expand Down Expand Up @@ -257,7 +260,12 @@ def barplot(x=None, y=None, data=None, **kwargs) -> None:
if x_arr.size == 0:
x_arr = np.full((y_arr.size,), "", dtype=str)
drawings.append(
Drawing(DrawingLibrary.seaborn, DrawingType.bar, DrawingData(x_arr, y_arr), kwargs)
Drawing(
DrawingLibrary.seaborn,
DrawingType.bar,
DrawingData(x_arr, y_arr),
kwargs,
)
)

def violinplot(*, x=None, y=None, data=None, **kwargs) -> None:
Expand Down Expand Up @@ -288,9 +296,7 @@ def heatmap(data=None, **kwargs) -> None:
if data is None:
return

curr_data = { # noqa: F841
"x": np.array(data, dtype=object)
}
curr_data = {"x": np.array(data, dtype=object)} # noqa: F841

drawing = Drawing(
DrawingLibrary.seaborn,
Expand All @@ -303,7 +309,10 @@ def heatmap(data=None, **kwargs) -> None:

def boxplot(x=None, y=None, data=None, **kwargs) -> None:
if data is None:
curr_data = {"x": np.array(x, dtype=object), "y": np.array(y, dtype=object)}
curr_data = {
"x": np.array(x, dtype=object),
"y": np.array(y, dtype=object),
}

drawing = Drawing(
DrawingLibrary.seaborn,
Expand Down
6 changes: 5 additions & 1 deletion hstest/testing/process_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ class ProcessWrapper:
initial_idle_wait_time = 150

def __init__(
self, *args, check_early_finish=False, register_output=True, register_io_handler=False
self,
*args,
check_early_finish=False,
register_output=True,
register_io_handler=False,
) -> None:
self.lock = Lock()

Expand Down
6 changes: 5 additions & 1 deletion hstest/testing/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

class TestRun:
def __init__(
self, test_num: int, test_count: int, test_case: TestCase, test_rummer: TestRunner
self,
test_num: int,
test_count: int,
test_case: TestCase,
test_rummer: TestRunner,
) -> None:
self._test_num: int = test_num
self._test_count: int = test_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class TestCommandLineArgsChanged(UserErrorTest):

@dynamic_test
def test(self):
main = TestedProgram('main')
main = TestedProgram("main")
main.start("123", "234", "345")
return wrong("")
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class TestCommandLineArgumentsFailed(UserErrorTest):
"""

def generate(self) -> List[TestCase]:
return [
TestCase(args=["-in", "123", "-out", "234"])
]
return [TestCase(args=["-in", "123", "-out", "234"])]

def check(self, reply: str, attach: Any) -> CheckResult:
return wrong("")
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class TestCommandLineArgumentsFailed2(UserErrorTest):
"""

def generate(self) -> List[TestCase]:
return [
TestCase(args=["-in", "123", "-out", "234"])
]
return [TestCase(args=["-in", "123", "-out", "234"])]

def check(self, reply: str, attach: Any) -> CheckResult:
return wrong("")
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ class TestCommandLineArgumentsFailedDynamicMethod(UserErrorTest):

@dynamic_test
def test1(self):
pr = TestedProgram('main')
pr = TestedProgram("main")
pr.start("-in", "123", "-out", "234")
return wrong('')
return wrong("")
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class TestCommandLineArgumentsFailedDynamicMethod2(UserErrorTest):

@dynamic_test
def test1(self):
pr = TestedProgram('main')
pr = TestedProgram("main")
pr.start("-in", "123", "-out", "234")
return wrong('')
return wrong("")
Loading