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_filereporter_source_handles_latin1(tmpdir):
from covimerage.coveragepy import FileReporter
with tmpdir.as_cwd():
with open('iso.txt', 'wb') as f:
f.write(b'Hellstr\xf6m')
with open('utf8.txt', 'wb') as f:
f.write(b'Hellstr\xc3\xb6m')
assert FileReporter('iso.txt').source().encode(
'utf-8') == b'Hellstr\xc3\xb6m'
assert FileReporter('iso.txt').source().encode(
'utf-8') == b'Hellstr\xc3\xb6m'
def test_filereporter():
from covimerage.coveragepy import FileReporter
f = FileReporter('/doesnotexist')
assert repr(f) == ""
with pytest.raises(coverage.misc.NoSource) as excinfo:
f.lines()
assert excinfo.value.args == (
"[Errno 2] No such file or directory: '/doesnotexist'",)
def test_filereporter_source_exception(mocker, devnull):
from covimerage.coveragepy import CoverageWrapperException, FileReporter
class CustomException(Exception):
pass
m = mocker.mock_open()
m.return_value.read.side_effect = CustomException
mocker.patch('covimerage.coveragepy.open', m)
f = FileReporter(devnull.name)
with pytest.raises(CoverageWrapperException) as excinfo:
f.source()
assert isinstance(excinfo.value.orig_exc, CustomException)
def file_reporter(self, filename):
return FileReporter(filename)
def _get_file_reporter(self, morf):
return FileReporter(morf)