Skip to content

Commit

Permalink
Now considers class doc string properly
Browse files Browse the repository at this point in the history
  • Loading branch information
gwthm-in committed Jan 22, 2018
1 parent 0802346 commit bf33cb9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
15 changes: 9 additions & 6 deletions pytest_pspec/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ def format_class_name(class_name, patterns):
formatted = ''

class_name = _remove_patterns(class_name, patterns)

for index, letter in enumerate(class_name):
if letter.isupper() and _has_lower_letter_besides(index, class_name):
formatted += ' '

formatted += letter
if ' ' not in class_name:
for index, letter in enumerate(class_name):
if letter.isupper() and \
_has_lower_letter_besides(index, class_name):
formatted += ' '

formatted += letter
else:
formatted = class_name

return formatted.strip()

Expand Down
13 changes: 4 additions & 9 deletions pytest_pspec/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ def parse(cls, nodeid, pattern_config):
node_parts[0],
pattern_config.files
)

class_name = node_parts[-2]
if '()' not in class_name:
class_name = None
else:
class_name = formatters.format_class_name(
node_parts[-3],
pattern_config.classes
)
class_name = formatters.format_class_name(
node_parts[1],
pattern_config.classes
)

return cls(title=title, class_name=class_name, module_name=module_name)

Expand Down
18 changes: 12 additions & 6 deletions pytest_pspec/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ def pytest_collection_modifyitems(config, items):
for item in items:
node = item.obj
parent = item.parent.obj
nodeid_parts = item.nodeid.split('::')
if node.__doc__:
nodeid_parts[-1] = node.__doc__.strip()
if parent.__doc__:
nodeid_parts[-2] = parent.__doc__.strip()
item._nodeid = '::'.join(nodeid_parts)
node_parts = item.nodeid.split('::')
node_str = node.__doc__ or node_parts[-1]
mode_str = node_parts[0]
klas_str = ''
node_parts_length = len(node_parts)

if node_parts_length > 3:
klas_str = parent.__doc__ or node_parts[-3]
elif node_parts_length > 2:
klas_str = parent.__doc__ or node_parts[-2]

item._nodeid = '::'.join([mode_str, klas_str, node_str])


class PspecTerminalReporter(TerminalReporter):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read(fname):

setup(
name='pytest-pspec',
version='0.0.2',
version='0.0.3',
description='A rspec format reporter for Python ptest',
long_description=read('README.rst'),
author='Gowtham Sai',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_parse_should_parse_node_id_attributes(self, pattern_config):
)

@pytest.mark.parametrize('nodeid,class_name', (
('tests/test_module.py::test_title', None),
('tests/test_module.py::::test_title', ''),
(
'tests/test_module.py::TestClassName::()::test_title',
formatters.format_class_name('TestClassName', ['Test*'])
Expand Down
15 changes: 15 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,18 @@ def test_a_feature_is_working():

expected = '\033[92m ✓ a feature is working\033[0m'
assert expected in result.stdout.str()

def test_should_print_class_name_if_doc_is_present(self, testdir):
"This is doc"

testdir.makepyfile("""
class TestBar(object):
"This is PySpec Class"
def test_a_feature_is_working(self):
assert True
""")

result = testdir.runpytest('--pspec')

expected = 'This is PySpec Class'
assert expected in result.stdout.str()

0 comments on commit bf33cb9

Please sign in to comment.