def test_file_reading_if_file_not_present_exception(self): with tempfile.NamedTemporaryFile(mode='a', delete=True) as fo: filename = fo.name for hash_string in self.test_data: fo.write(hash_string + '\n') fo.close() self.assertRaises(FileNotFoundError, player_parser.getFileConents(filename))
def test_file_reading_if_file_present(self): # mock.patch did not worked out, for some reason nosetests can't run, # so used tempfile with tempfile.NamedTemporaryFile(mode='a', delete=False) as fo: filename = fo.name for hash_string in self.test_data: fo.write(hash_string + '\n') fo.close() output = player_parser.getFileConents(filename) self.assertEqual(output, self.test_data) os.remove(filename) # because we're specified opposite in tempfile