def test_pyfiles_package(monkeypatch): monkeypatch.setattr(os.path, 'abspath', pretend.call_recorder(lambda x: '/spam')) monkeypatch.setattr(os.path, 'isdir', pretend.call_recorder(lambda x: True)) walk_results = [ ('spam', [], ['__init__.py', 'spam', 'ham.py']), ('spam/dub', [], ['bass.py', 'dropped']), ] monkeypatch.setattr(os, 'walk', pretend.call_recorder(lambda x: walk_results)) assert list(common.pyfiles('spam')) == \ ['spam/__init__.py', 'spam/ham.py', 'spam/dub/bass.py']
def test_pyfiles_file_no_dice(monkeypatch): monkeypatch.setattr(os.path, 'abspath', pretend.call_recorder(lambda x: '/spam/ham')) with pytest.raises(ValueError): list(common.pyfiles('spam'))
def test_pyfiles_file(monkeypatch): monkeypatch.setattr(os.path, 'abspath', pretend.call_recorder(lambda x: '/spam/ham.py')) assert list(common.pyfiles('spam')) == ['/spam/ham.py']