def test_parser_file_init_with_content(self, mock_recursive_find): try: str_type = basestring # Python 2.x. except NameError: str_type = str # Python 3.x. with mock.patch.object( builtins, 'open', mock.mock_open( read_data='The cake is a lie!\nThe cake is a lie!')): my_fileparser = FileParser(pathname='./', filename='text.txt') self.assertIsInstance(my_fileparser.stream, str_type) self.assertTrue(my_fileparser.stream == 'The cake is a lie!\nThe cake is a lie!')
def test_parser_file_init_no_file(self, mock_recursive_find): with self.assertRaises(IOError): FileParser(pathname='/dev/', filename='null')