Skip to content

Commit

Permalink
Extend test case for example metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
chdorner committed Jan 20, 2021
1 parent c384190 commit dcbeea7
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions tests/shared/nlu/training_data/formats/test_rasa_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
)


MULTILINE_INTENT_EXAMPLES = f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
MULTILINE_INTENT_EXAMPLES = f"""version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
nlu:
- intent: intent_name
examples: |
- how much CO2 will that use?
- how much carbon will a one way flight from [new york]{{"entity": "city", "role": "from"}} to california produce?
- what's the carbon footprint of a flight from london to new york?
- how much co2 to new york?
- how much co2 is produced on a return flight from london to new york?
"""

MULTILINE_INTENT_EXAMPLE_WITH_SYNONYM = """
Expand All @@ -43,7 +45,7 @@
- how much carbon will a one way flight from [new york]{"entity": "city", "role": "from"} to california produce?
"""

INTENT_EXAMPLES_WITH_METADATA = """
INTENT_EXAMPLES_WITH_METADATA = f"""version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
nlu:
- intent: intent_name
metadata:
Expand All @@ -54,7 +56,14 @@
metadata:
sentiment: positive
- text: |
how much carbon will a one way flight from [new york]{"entity": "city", "role": "from"} to california produce?
how much carbon will a one way flight from [new york]{{"entity": "city", "role": "from"}} to california produce?
metadata: co2-trip-calculation
- text: |
how much CO2 to [new york]{{"entity": "city", "role": "to"}}?
- intent: greet
examples: |
- Hi
- Hello
"""

MINIMAL_VALID_EXAMPLE = """
Expand Down Expand Up @@ -141,7 +150,7 @@ def test_multiline_intent_is_parsed(example: Text):

assert not len(record)

assert len(training_data.training_examples) == 2
assert len(training_data.training_examples) == 5
assert training_data.training_examples[0].get(
INTENT
) == training_data.training_examples[1].get(INTENT)
Expand All @@ -156,13 +165,16 @@ def test_intent_with_metadata_is_parsed():

assert not len(record)

assert len(training_data.training_examples) == 2
example_1, example_2 = training_data.training_examples
assert len(training_data.training_examples) == 5
example_1, example_2, *other_examples = training_data.training_examples
assert example_1.get(METADATA) == {
METADATA_INTENT: ["johnny"],
METADATA_EXAMPLE: {"sentiment": "positive"},
}
assert example_2.get(METADATA) == {METADATA_INTENT: ["johnny"]}
assert example_2.get(METADATA) == {
METADATA_INTENT: ["johnny"],
METADATA_EXAMPLE: "co2-trip-calculation",
}


# This test would work only with examples that have a `version` key specified
Expand Down

0 comments on commit dcbeea7

Please sign in to comment.