Skip to content

Commit

Permalink
Merge pull request #79 from brunohjs/#78
Browse files Browse the repository at this point in the history
78 - Parameter `--exclude` to exclude utters and actions
  • Loading branch information
brunohjs committed Oct 8, 2023
2 parents a56cd0f + 7d8eb91 commit bffaa97
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 17 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.5] - In progress...
## [1.4.0] - In progress...

### Added
- [#73](https://github.com/brunohjs/rasa-model-report/issues/73) Created section with element count on model report. Additionally, now all tables elements are numbered.
- [#78](https://github.com/brunohjs/rasa-model-report/issues/78) Created `--exclude` CLI command parameter. This command is used to exclude utters and actions from end-to-end test coverage.

### Fixed
- [#75](https://github.com/brunohjs/rasa-model-report/issues/75) Fixed bug with utters in actions that weren't being covered by the end-to-end tests.
Expand Down Expand Up @@ -88,7 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- [#16](https://github.com/brunohjs/rasa-model-report/issues/16) Created a handler for retrieval intents in the report.

[1.3.5]: https://github.com/brunohjs/rasa-model-report/compare/1.3.4...1.3.5
[1.3.5]: https://github.com/brunohjs/rasa-model-report/compare/1.3.4...1.4.0
[1.3.4]: https://github.com/brunohjs/rasa-model-report/compare/1.3.3...1.3.4
[1.3.3]: https://github.com/brunohjs/rasa-model-report/compare/1.3.2...1.3.3
[1.3.2]: https://github.com/brunohjs/rasa-model-report/compare/1.3.0...1.3.2
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ There are parameters that can be used. Available options are below:
path)
--disable-nlu Disable processing NLU sentences. NLU section will
not be generated in the report. Required Rasa API.
-e, --exclude LIST List of utter and actions that will be exclude in
the E2E test coverage. Use commas to separate items.
Example: utter_greet,utter_goodbye,action_listen
-h, --help Show this help message.
--model-link TEXT Model download link. It's only displayed in the
report to model download.
Expand Down
3 changes: 3 additions & 0 deletions rasa_model_report/controllers/e2e_coverage_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(
rasa_path: str,
output_path: str,
actions_path: str,
exclude: List[str],
project_name: str,
project_version: str,
**kwargs: Dict[str, Any]
Expand All @@ -38,6 +39,7 @@ def __init__(
self._entities: List[str] = []
self._actions: List[str] = []
self._total_rate: float = 0
self._exclude = exclude
self.json: JsonController = JsonController(rasa_path, output_path, project_name, project_version)

self._load_domain_elements()
Expand Down Expand Up @@ -72,6 +74,7 @@ def _load_domain_elements(self) -> None:
setattr(self, f"_{element}", getattr(self, f"_{element}") + data)
self._actions = list(dict.fromkeys(self._actions))
self._actions = self._exclude_special_actions()
self._actions = utils.list_diff(self._actions, self._exclude)
self._actions = utils.list_diff(self._actions, self.get_utters_in_actions())

def _generate(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions rasa_model_report/controllers/markdown_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(
rasa_path,
output_path,
kwargs.get("actions_path"),
kwargs.get("exclude", []),
project_name,
project_version
)
Expand Down
1 change: 1 addition & 0 deletions rasa_model_report/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
RASA_API_URL = "http://localhost:5005"
RASA_PATH = "./"
RASA_VERSION = None
EXCLUDE = []
12 changes: 11 additions & 1 deletion rasa_model_report/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
help="Disable processing NLU sentences. NLU section will not be generated "
"in the report. Required Rasa API."
)
@click.option(
"--exclude",
"-e",
required=False,
multiple=True,
help="List of utter and actions that will be exclude in the E2E test coverage. Use commas to separate items. "
"Example: utter_greet,utter_goodbye,action_listen"
)
@click.help_option(
"--help",
"-h",
Expand Down Expand Up @@ -101,6 +109,7 @@
def main(
actions_path,
disable_nlu,
exclude,
model_link,
no_images,
output_path, path,
Expand All @@ -124,6 +133,7 @@ def main(
model_link=model_link,
actions_path=actions_path,
no_images=no_images,
precision=precision
precision=precision,
exclude=[item for row in exclude for item in row.split(",")]
)
return report
25 changes: 18 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

def pytest_generate_tests(metafunc):
rasa_dirs = glob.glob("tests/mocks/rasa.v*")
metafunc.fixturenames.append('rasa_path')
metafunc.parametrize('rasa_path', rasa_dirs)
metafunc.fixturenames.append("rasa_path")
metafunc.parametrize("rasa_path", rasa_dirs)


@pytest.fixture(autouse=True)
Expand All @@ -33,13 +33,24 @@ def load_controllers(rasa_path):
project_name = "test-project"
project_version = "0.0.0"
rasa_version = "0.0.0"
exclude = []
utils.load_mock_payloads()
controller = Controller(rasa_path, output_path, project_name, project_version)
json_controller = JsonController(rasa_path, output_path, project_name, project_version)
csv_controller = CsvController(rasa_path, output_path, project_name, project_version)
nlu_controller = NluController(rasa_path, output_path, project_name, project_version)
e2e_coverage_controller = E2ECoverageController(rasa_path, output_path, actions_path, project_name, project_version)
markdown_controller = MarkdownController(rasa_path, output_path, project_name, rasa_version, project_version)
json_controller = JsonController(
rasa_path, output_path, project_name, project_version
)
csv_controller = CsvController(
rasa_path, output_path, project_name, project_version
)
nlu_controller = NluController(
rasa_path, output_path, project_name, project_version
)
e2e_coverage_controller = E2ECoverageController(
rasa_path, output_path, actions_path, exclude, project_name, project_version
)
markdown_controller = MarkdownController(
rasa_path, output_path, project_name, rasa_version, project_version
)
pytest.controller = controller
pytest.json_controller = json_controller
pytest.csv_controller = csv_controller
Expand Down
6 changes: 6 additions & 0 deletions tests/mocks/rasa.v2/domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ responses:
utter_test_2:
- text: "Test 2"

utter_uncovered:
- text: "Uncovered utter"

utter_another_uncovered:
- text: "Another uncovered utter"

session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
6 changes: 6 additions & 0 deletions tests/mocks/rasa.v3/domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ responses:
utter_test_2:
- text: "Test 2"

utter_uncovered:
- text: "Uncovered utter"

utter_another_uncovered:
- text: "Another uncovered utter"

session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
3 changes: 2 additions & 1 deletion tests/test_e2e_coverage_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def execute_before_each_test(rasa_path):
actions_path = None
project_name = "test-project"
project_version = "0.0.0"
exclude = []
e2e_coverage_controller = E2ECoverageController(
rasa_path, output_path, actions_path, project_name, project_version
rasa_path, output_path, actions_path, exclude, project_name, project_version
)
pytest.e2e_coverage_controller = e2e_coverage_controller
yield
Expand Down
40 changes: 34 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,40 @@
from tests import utils


@responses.activate
def test_main_with_exclude(rasa_path):
runner = CliRunner()
result = runner.invoke(
main,
[
"--path",
rasa_path,
"--exclude",
"utter_uncovered,utter_another_uncovered",
"-e",
"utter_goodbay",
],
)
assert os.path.isfile("model_report.md") is True
assert utils.check_model_report_sections("model_report.md") is True
assert utils.check_model_report_images("model_report.md") is True
assert (
utils.check_model_report_text(
"model_report.md", ["utter_uncovered", "utter_another_uncovered"]
)
is False
)
assert result.exit_code == 0
assert result.output == ""


@responses.activate
def test_main_with_valid_path(rasa_path):
runner = CliRunner()
result = runner.invoke(main, ["--path", rasa_path])
assert os.path.isfile("model_report.md")
assert utils.check_model_report_sections("model_report.md")
assert utils.check_model_report_images("model_report.md")
assert os.path.isfile("model_report.md") is True
assert utils.check_model_report_sections("model_report.md") is True
assert utils.check_model_report_images("model_report.md") is True
assert result.exit_code == 0
assert result.output == ""

Expand All @@ -23,7 +50,7 @@ def test_main_with_invalid_path():
utils.load_mock_payloads()
runner = CliRunner()
result = runner.invoke(main, [])
assert not os.path.isfile("model_report.md")
assert os.path.isfile("model_report.md") is False
assert result.exit_code == 0
assert result.output == ""

Expand All @@ -33,14 +60,15 @@ def test_main_with_no_images(rasa_path):
utils.load_mock_payloads()
runner = CliRunner()
result = runner.invoke(main, ["--path", rasa_path, "--no-images"])
assert os.path.isfile("model_report.md")
assert not utils.check_model_report_images("model_report.md")
assert os.path.isfile("model_report.md") is True
assert utils.check_model_report_images("model_report.md") is False
assert result.exit_code == 0
assert result.output == ""


def test_main_help():
runner = CliRunner()
result = runner.invoke(main, ["--help"])
assert os.path.isfile("model_report.md") is False
assert result.exit_code == 0
assert result.output
10 changes: 10 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ def check_model_report_images(model_report_path):
"/DIETClassifier_confusion_matrix.png" in file_data and \
"/story_confusion_matrix.png" in file_data and \
"/intent_histogram.png" in file_data


def check_model_report_text(model_report_path, texts):
file = open(model_report_path, encoding="utf-8")
file_data = file.read()
file.close()
if isinstance(texts, str):
return texts in file_data
else:
return all([text in file_data for text in texts])

0 comments on commit bffaa97

Please sign in to comment.