result = system.get_file_contents(interesting_file.path)
assert result == "0\n1"
+ def test_path_empty_returns_default(self, fake_filesystem):
+ interesting_file = fake_filesystem.create_file('/tmp/fake-file', contents="")
+ result = system.get_file_contents(interesting_file.path, 'default')
+ assert result == 'default'
+
+ def test_path_whitespace_returns_default(self, fake_filesystem):
+ interesting_file = fake_filesystem.create_file('/tmp/fake-file', contents=" \n\t")
+ result = system.get_file_contents(interesting_file.path, 'default')
+ assert result == 'default'
+
def test_exception_returns_default(self):
with patch('builtins.open') as mocked_open:
mocked_open.side_effect = Exception()
return contents
try:
with open(path, 'r') as open_file:
- contents = open_file.read().strip()
+ contents = open_file.read().strip() or default
except Exception:
logger.exception('Failed to read contents from: %s' % path)