Esempio n. 1
0
 def test_should_output_for_not_step(self):
     """ Scenariusz: format for not a step """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = 'Scenario: some number'
     status = 'pass'
     duration = 0.01
     node = Mock(Scenario)
     obj.output(node, line, status, duration)
     # Assert
     expected = '%s\n' % line
     self.assertEqual(stream.getvalue(), expected)
Esempio n. 2
0
 def test_should_output_for_feature(self):
     """ Scenariusz: format for feature """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = 'Feature: some feature'
     status = 'pass'
     duration = 0.01
     node = Mock(Feature)
     obj.output(node, line, status, duration)
     # Assert
     expected = '\n%s\n' % line
     self.assertEqual(stream.getvalue(), expected)
Esempio n. 3
0
 def test_should_output_for_error(self):
     """ Scenariusz: format for error """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = 'Given some number'
     status = 'error'
     duration = 0.01
     node = Mock(Step)
     obj.output(node, line, status, duration)
     # Assert
     expected = '%-60s # error 0.010s\n' % line
     self.assertEqual(stream.getvalue(), expected)
Esempio n. 4
0
 def test_should_output_for_error(self):
     """ Scenariusz: format for error """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = 'Given some number'
     status = 'error'
     duration = 0.01
     node = Mock(Step)
     obj.output(node, line, status, duration)
     # Assert
     expected = '%-60s # error 0.010s\n' % line
     self.assertEqual(stream.getvalue(), expected)
Esempio n. 5
0
 def test_should_output_for_not_step(self):
     """ Scenariusz: format for not a step """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = 'Scenario: some number'
     status = 'pass'
     duration = 0.01
     node = Mock(Scenario)
     obj.output(node, line, status, duration)
     # Assert
     expected = '%s\n' % line
     self.assertEqual(stream.getvalue(), expected)
Esempio n. 6
0
 def test_should_output_for_feature(self):
     """ Scenariusz: format for feature """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = "Feature: some feature"
     status = "pass"
     duration = 0.01
     node = Mock(Feature)
     obj.output(node, line, status, duration)
     # Assert
     expected = "\n%s\n" % line
     assert stream.getvalue() == expected
Esempio n. 7
0
 def test_should_output_for_not_step(self):
     """ Scenariusz: format for not a step """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = "Scenario: some number"
     status = "pass"
     duration = 0.01
     node = Mock(Scenario)
     obj.output(node, line, status, duration)
     # Assert
     expected = "%s\n" % line
     assert stream.getvalue() == expected
Esempio n. 8
0
 def test_should_output_for_error(self):
     """ Scenariusz: format for error """
     # Arrange
     stream = StringIO()
     obj = PlainTextFormatter(stream)
     # Act
     line = "Given some number"
     status = "error"
     duration = 0.01
     node = Mock(Step)
     obj.output(node, line, status, duration)
     # Assert
     expected = "%-60s # error 0.010s\n" % line
     assert stream.getvalue() == expected
Esempio n. 9
0
def run(filename,
        suite,
        as_str=None,
        scenario=r'.*',
        verbose=False,
        show_all_missing=True,
        **kwargs):  # NOQA
    """Parse file and run tests on given suite.

    :param str filename: file name
    :param unittest.TestCase suite: TestCase instance
    :param string as_str: None to use file or a string containing the feature to parse
    :param string scenario: a regex pattern to match the scenario to run
    :param boolean verbose: be verbose
    :param boolean show_all_missing: show all missing steps
    """
    formatter = kwargs.get('formatter', None)
    if verbose and not formatter:
        if has_color_support():
            formatter = ColorTextFormatter()
        else:
            formatter = PlainTextFormatter()
        kwargs['formatter'] = formatter
    kwargs['show_all_missing'] = show_all_missing
    parser = Parser()
    ast = parser.parse_file(filename, scenario=scenario) if as_str is None \
        else parser.parse_as_str(filename, as_str, scenario=scenario)
    return ast.evaluate(suite, **kwargs)
Esempio n. 10
0
def run(filename,
        suite,
        as_str=None,
        scenario=r".*",
        verbose=False,
        show_all_missing=True,
        **kwargs):  # NOQA
    """Parse file and run tests on given suite.

    :param str filename: file name
    :param unittest.TestCase suite: TestCase instance
    :param string as_str: None to use file or a string containing the feature to parse
    :param string scenario: a regex pattern to match the scenario to run
    :param boolean verbose: be verbose
    :param boolean show_all_missing: show all missing steps
    """
    formatter = kwargs.get("formatter", None)
    if verbose and not formatter:
        if has_color_support():
            formatter = ColorTextFormatter()
        else:
            formatter = PlainTextFormatter()
        kwargs["formatter"] = formatter
    kwargs["show_all_missing"] = show_all_missing
    if as_str is None:
        source = File(filename)
    else:
        source = Text(as_str, filename)
    feature = Parser().parse_features(source)
    return execute_script(feature, suite, scenario=scenario, **kwargs)
Esempio n. 11
0
def verify(script,
           suite,
           scenario: str = ".*",
           config: str = "default") -> None:
    """Verifies script with steps from suite.

    :param script: feature script
    :param suite: object with steps defined
    :param str scenario: regex pattern for selecting single scenarios
    :param str config: section from configuration to apply

    Script can be passed directly to verify method as first argument.

    .. code-block:: python

        >>> from morelia import verify
        >>> verify(
        ...    \"""
        ...    Feature: Addition
        ...    Scenario: Add two numbers
        ...      Given I have entered 50 into the calculator
        ...      And I have entered 70 into the calculator
        ...      When I press add
        ...      Then the result should be 120 on the screen
        ...    \""",
        ...    test_case_with_steps,
        )

    When given path to file with script morelia will read that file and verify:

    .. code-block:: python

        >>> verify('calculator.feature', test_case_with_steps)

    Similary url pointing to script can be given:

    .. code-block:: python

        >>> verify('http://example.com/calculator.feature', test_case_with_steps)

    Two last invocations will work only for single line strings.
    If it starts with "http[s]://" it is considered an url.
    If it ends with ".feature" it is considered a file.

    To explicity mark what type of parameter it can be wrapped in helper classes:

    - :py:func:`File`
    - :py:func:`Url`
    - :py:func:`Text`

        >>> from morelia import verify, File, Text, Url
        >>> verify(File('calculator.feature'), test_case_with_steps)
        >>> verify(Url('http://example.com/calculator.feature'), test_case_with_steps)
        >>> verify(
        ...    Text(\"""
        ...    Feature: Addition
        ...    Scenario: Add two numbers
        ...      Given I have entered 50 into the calculator
        ...      And I have entered 70 into the calculator
        ...      When I press add
        ...      Then the result should be 120 on the screen
        ...    \"""),
        ...    test_case_with_steps,
        )

    """
    conf = TOMLConfig(config)
    script = _coerce_type(script)
    feature = Parser().parse_features(script)
    execute_script(feature,
                   suite,
                   scenario=scenario,
                   config=conf,
                   formatter=PlainTextFormatter())