commit e5046f73a1bfe49cfa7a0b312d11c558c7e47818 Author: Damian Johnson atagar@torproject.org Date: Wed Apr 1 09:51:31 2015 -0700
Test when tail() is unable to read the file --- stem/util/system.py | 2 ++ test/unit/descriptor/reader.py | 5 ++--- test/unit/util/system.py | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py index fd62b9d..56f3da5 100644 --- a/stem/util/system.py +++ b/stem/util/system.py @@ -756,6 +756,8 @@ def tail(target, lines = None): :param int lines: number of lines to read
:returns: **list** of lines the file ends with + + :raises: **IOError** if unable to read the file """
if isinstance(target, str): diff --git a/test/unit/descriptor/reader.py b/test/unit/descriptor/reader.py index debb88a..eaea7ea 100644 --- a/test/unit/descriptor/reader.py +++ b/test/unit/descriptor/reader.py @@ -635,8 +635,7 @@ class TestDescriptorReader(unittest.TestCase): it is located. """
- test_listing_file = open(self.test_listing_path, 'w') - test_listing_file.write(contents) - test_listing_file.close() + with open(self.test_listing_path, 'w') as test_listing_file: + test_listing_file.write(contents)
return self.test_listing_path diff --git a/test/unit/util/system.py b/test/unit/util/system.py index 98cfb8d..e3de4d8 100644 --- a/test/unit/util/system.py +++ b/test/unit/util/system.py @@ -9,6 +9,7 @@ import functools import ntpath import os import posixpath +import tempfile import unittest
from stem import str_type @@ -391,6 +392,14 @@ class TestSystem(unittest.TestCase): self.assertEqual(14, len(system.tail(path))) self.assertEqual(14, len(system.tail(path, 200)))
+ self.assertRaises(IOError, system.tail, '/path/doesnt/exist') + + fd, temp_path = tempfile.mkstemp() + os.chmod(temp_path, 0o077) # remove read permissions + self.assertRaises(IOError, system.tail, temp_path) + os.close(fd) + os.remove(temp_path) + @patch('stem.util.system.call') @patch('stem.util.system.is_available', Mock(return_value = True)) def test_bsd_jail_id(self, call_mock):