Skip to content

Commit

Permalink
test: update markers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreCameron committed May 8, 2020
1 parent 8a92be3 commit 49b34ff
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
16 changes: 13 additions & 3 deletions Makefile
Expand Up @@ -82,11 +82,21 @@ build-doc: ## Build python documentation using sphinx
# Unit tests
# ----------

test-pytest: ## Launch python tests
@echo "+++test-pytest:"
${PYTEST} ${TEST_PATH} -m "ut" --cov-report=xml
test-pytest-ut: ## Launch pytest ut
${PYTEST} ${TEST_PATH} -m "ut"
.PHONY: test-pytest-ut

test-pytest-e2e: ## Launch pytest e2e
${PYTEST} ${TEST_PATH} -m "e2e"
.PHONY: test-pytest-e2e

test-pytest-tuto: ## Launch pytest tuto
${PYTEST} ${TEST_PATH} -m "tuto"
.PHONY: test-pytest-tuto

test-pytest: ## Launch pytests
@echo "+++test-pytest:"
${PYTEST} ${TEST_PATH} --cov-report=xml
.PHONY: test-pytest

tests-python: ## Launch all python tests
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -4,6 +4,7 @@ Dirty tricks to run python notebooks

[![PyPI version](https://badge.fury.io/py/boar.svg)](https://badge.fury.io/py/boar)
![test](https://github.com/alexandreCameron/boar/workflows/test/badge.svg)
[![codecov](https://codecov.io/gh/alexandreCameron/boar/branch/master/graph/badge.svg)](https://codecov.io/gh/alexandreCameron/boar)
[![Documentation Status](https://readthedocs.org/projects/boar/badge/?version=latest)](https://boar.readthedocs.io/en/latest/?badge=latest)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/alexandreCameron/boar/master)

Expand Down
3 changes: 2 additions & 1 deletion src/boar/utils/split.py
Expand Up @@ -8,7 +8,8 @@ def split_lines_by_block(
start_tag: str,
end_tag: str,
) -> List[Dict[str, Union[str, bool]]]:
tag_type = start_tag.split("_")[0].split("# ")[1]
print(source_to_split, start_tag, end_tag)
tag_type = start_tag.split("# ")[1].split("_")[0]
start_splits = split_lines_with_block_tag(source_to_split, start_tag)
end_splits = split_lines_with_block_tag(start_splits[1], end_tag)

Expand Down
37 changes: 29 additions & 8 deletions tests/test_linting_e2e.py
Expand Up @@ -8,12 +8,13 @@
from boar.__init__ import Notebook, BoarError


@pytest.mark.e2e
@pytest.mark.parametrize("notebook_path,expected_incorrect_lint_files", [
(Path(Notebook._02.value, "0-execution.ipynb"), []),
(Notebook._02.value, [
'/home/alex/Desktop/github/boar/notebook/02-lint/1-execution.ipynb',
'/home/alex/Desktop/github/boar/notebook/02-lint/level-1/one-execution.ipynb',
'/home/alex/Desktop/github/boar/notebook/02-lint/unstructured-executions.ipynb',
'notebook/02-lint/1-execution.ipynb',
'notebook/02-lint/level-1/one-execution.ipynb',
'notebook/02-lint/unstructured-executions.ipynb',
]),
(Notebook._00.value, [])
])
Expand All @@ -35,19 +36,30 @@ def test_lint_notebook_returns_correct_values(
recursion_level=recursion_level
)

# TODO Parse message to remove str up to notebook part
parsed_incorrect_lint_files = []
for fname in incorrect_lint_files:
parsed_name = []
for part in reversed(Path(fname).parts):
parsed_name.append(part)
if part == "notebook":
break
parsed_incorrect_lint_files.append(Path(*parsed_name[::-1]).as_posix())

# Then
assert incorrect_lint_files == expected_incorrect_lint_files
assert parsed_incorrect_lint_files == expected_incorrect_lint_files


@pytest.mark.e2e
def test_lint_notebook_returns_error_when_fail():
# Given
from boar.linting import lint_notebook
error_msg = "Incorrect error message"
expected_error_msg = (
f"Linting issues in:\n" +
f"/home/alex/Desktop/github/boar/notebook/02-lint/1-execution.ipynb\n" +
f"/home/alex/Desktop/github/boar/notebook/02-lint/level-1/one-execution.ipynb\n" +
f"/home/alex/Desktop/github/boar/notebook/02-lint/unstructured-executions.ipynb"
f"notebook/02-lint/1-execution.ipynb\n" +
f"notebook/02-lint/level-1/one-execution.ipynb\n" +
f"notebook/02-lint/unstructured-executions.ipynb"
)
inline = False
verbose = False
Expand All @@ -59,5 +71,14 @@ def test_lint_notebook_returns_error_when_fail():
_, error_msg, _ = exc_info()
pass

# TODO Parse message to remove str up to notebook part
parsed_error_lines = []
for line in str(error_msg).split("\n"):
if "notebook" in line:
parsed_error_lines.append("notebook" + line.split("notebook")[1])
else:
parsed_error_lines.append(line)
parsed_error_msg = "\n".join(parsed_error_lines)

# Then
assert str(error_msg) == expected_error_msg
assert parsed_error_msg == expected_error_msg
1 change: 0 additions & 1 deletion tests/utils/test_parse.py
Expand Up @@ -170,7 +170,6 @@ def test_remove_output_returns_correct_values(
cleaned_content = remove_output(file_path, inline)

# Then
print(cells)
assert mock_manager.mock_calls == expected_function_calls
assert cleaned_content == expected_cleaned_content

Expand Down
23 changes: 12 additions & 11 deletions tests/utils/test_split.py
Expand Up @@ -6,6 +6,7 @@
from boar.__init__ import Tag


@pytest.mark.ut
@patch("boar.utils.split.split_lines_with_block_tag")
def test_split_lines_by_block_calls_functions_in_order(
mock_split_lines_with_block_tag,
Expand All @@ -15,11 +16,11 @@ def test_split_lines_by_block_calls_functions_in_order(
source_to_split = "012"
start_splits = ["0", "12"]
end_splits = ["1", "2"]
start_tag, end_tag = "", ""
start_tag, end_tag = "# tag_start", "# tag_end"
expected_splits = [
{"code": start_splits[0], "export": False},
{"code": end_splits[0], "export": True},
{"code": end_splits[1], "export": False},
{"apply": False, "code": "0", "type": "tag"},
{"apply": True, "code": "1", "type": "tag"},
{"apply": False, "code": "2", "type": "tag"},
]

# Thus
Expand Down Expand Up @@ -65,15 +66,15 @@ def test_split_lines_with_block_tag_returns_correct_values(

@pytest.mark.ut
@pytest.mark.parametrize("source_to_split,expected_splits", [
(f"a", [{'apply': False, 'code': 'a', 'type': 'export'}]),
(f"a", [{"apply": False, "code": "a", "type": "export"}]),
(f"b {Tag.EXPORT_LINE.value}",
[{'apply': False, 'code': '', 'type': 'export'},
{'apply': True, 'code': f'b {Tag.EXPORT_LINE.value}', 'type': 'export'},
{'apply': False, 'code': '', 'type': 'export'}]),
[{"apply": False, "code": "", "type": "export"},
{"apply": True, "code": f"b {Tag.EXPORT_LINE.value}", "type": "export"},
{"apply": False, "code": "", "type": "export"}]),
(f"a\nb {Tag.EXPORT_LINE.value}\nc",
[{'apply': False, 'code': 'a', 'type': 'export'},
{'apply': True, 'code': f'b {Tag.EXPORT_LINE.value}', 'type': 'export'},
{'apply': False, 'code': 'c', 'type': 'export'}]),
[{"apply": False, "code": "a", "type": "export"},
{"apply": True, "code": f"b {Tag.EXPORT_LINE.value}", "type": "export"},
{"apply": False, "code": "c", "type": "export"}]),
])
def test_split_lines_with_line_tag_returns_correct_value(
source_to_split: str,
Expand Down

0 comments on commit 49b34ff

Please sign in to comment.