Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_collect_ignore_path(ignore_path):
"""Check if ``collect_tests`` don't collect tests on the ignore paths."""
tests = collector.collect_tests('tests/data', [ignore_path])
assert 'tests/data/ignore_dir/test_ignore_dir.py' not in tests
assert 'tests/data/test_sample.py' in tests
assert len(tests['tests/data/test_sample.py']) == 4
def test_collect_tests(path):
"""Check if ``collect_tests`` 'tests/data'collect tests."""
tests = collector.collect_tests(path)
assert 'tests/data/test_sample.py' in tests
assert len(tests['tests/data/test_sample.py']) == 4
# Check if we are not doing a specific python module collection
if path.endswith('.py'):
return
assert 'tests/data/ignore_dir/test_ignore_dir.py' in tests
assert len(tests['tests/data/ignore_dir/test_ignore_dir.py']) == 2
def test_parse_docstring():
"""Check ``parse_docstring`` parser result."""
docstring = """
:field1: value1
:field2: value2
:field3:
* item 1
* item 2
"""
assert parser.parse_docstring(docstring) == {
'field1': 'value1',
'field2': 'value2',
'field3': '<ul class="simple">\n<li><p>item 1</p></li>\n'
'<li><p>item 2</p></li>\n</ul>\n',
def test_parse_none_docstring(docstring):
"""Check ``parse_docstring`` returns empty dict on empty input."""
assert parser.parse_docstring(docstring) == {}
def test_parse_docstring_special_characters():
"""Check ``parse_docstring`` parser result."""
docstring = """
Description with an special character like é
:field1: value with an special character like é
"""
assert parser.parse_docstring(docstring) == {
u'field1': u'value with an special character like é',
}
def test_parse_rst_special_characters():
"""Check if ``parse_rst`` plays nice with special characters."""
assert parser.parse_rst(u'String with special character like é') == (
u'<div class="document">\n'
u'<p>String with special character like é</p>\n'</div>
def test_parse_rst_empty_string(string):
"""Check ``parse_rst`` returns empty string on empty input."""
assert parser.parse_rst(string) == ''
'field1\n'
'<p>value1</p>\n'
'\n'
'\n'
'field2\n'
'<p>value2</p>\n'
'\n'
'\n'
'field3\n'
'<p></p>\n'
'\n'
'\n'
'\n'
'\n'
)
assert parser.parse_rst(
docstring, parser.TableFieldListTranslator) == expected
def test_not_is_test_module(filename):
"""Check ``is_test_module`` working for invalid filenames."""
assert not collector.is_test_module(filename)
def test_create_xml_testcase():
"""Check if create_xml_testcase creates the expected XML tag."""
testcase = mock.MagicMock()
testcase.name = 'test_it_works'
testcase.parent_class = 'FeatureTestCase'
testcase.testmodule = 'tests/test_feature.py'
testcase.docstring = 'Test feature docstring'
testcase.fields = {
field: field for field in
default_config.TESTCASE_FIELDS + default_config.TESTCASE_CUSTOM_FIELDS
}
testcase.fields['parametrized'] = 'yes'
config = BetelgeuseConfig()
generated = ElementTree.tostring(
create_xml_testcase(config, testcase, '{path}#{line_number}'),
encoding='unicode'
)
assert generated == (
'