def test_with_missing_file(self): output_file = io.StringIO() ignore = StubFile() eradicate.main(argv=['my_fake_program', '--in-place', '.fake'], standard_out=output_file, standard_error=ignore) self.assertFalse(output_file.getvalue())
def test_in_place(self): with temporary_file("""\ # x * 3 == False # x is a variable """) as filename: output_file = io.StringIO() eradicate.main(argv=['my_fake_program', '--in-place', filename], standard_out=output_file, standard_error=None) with open(filename) as f: self.assertEqual("""\ # x is a variable """, f.read())
def test_diff(self): with temporary_file("""\ # x * 3 == False # x is a variable """) as filename: output_file = io.StringIO() eradicate.main(argv=['my_fake_program', filename], standard_out=output_file, standard_error=None) self.assertEqual("""\ @@ -1,2 +1 @@ -# x * 3 == False # x is a variable """, '\n'.join(output_file.getvalue().split('\n')[2:]))
def test_ignore_hidden_directories(self): with temporary_directory() as directory: with temporary_directory(prefix='.', directory=directory) as inner_directory: with temporary_file("""\ # x * 3 == False # x is a variable """, directory=inner_directory): output_file = io.StringIO() eradicate.main( argv=['my_fake_program', '--recursive', directory], standard_out=output_file, standard_error=None) self.assertEqual('', output_file.getvalue().strip())
def test_whitelist_extend(self): mock_update = mock.Mock() with mock.patch.object(eradicate.Eradicator, 'update_whitelist', mock_update): with temporary_file("# empty") as filename: result = eradicate.main(argv=['my_fake_program', '--whitelist-extend', 'foo #bar', filename], standard_out=None, standard_error=None) self.assertTrue(result is None) mock_update.assert_called_once_with(["foo ", "bar"], True)
def test_returns_None_if_no_error_request(self): with temporary_file("""\ # x * 3 == False # x is a variable """) as filename: output_file = io.StringIO() result = eradicate.main(argv=['my_fake_program', filename], standard_out=output_file, standard_error=None) self.assertTrue(result is None)
def test_recursive(self): with temporary_directory() as directory: with temporary_file("""\ # x * 3 == False # x is a variable """, directory=directory): output_file = io.StringIO() eradicate.main(argv=['my_fake_program', '--recursive', directory], standard_out=output_file, standard_error=None) self.assertEqual("""\ @@ -1,2 +1 @@ -# x * 3 == False # x is a variable """, '\n'.join(output_file.getvalue().split('\n')[2:]))
def test_ignore_hidden_directories(self): with temporary_directory() as directory: with temporary_directory(prefix='.', directory=directory) as inner_directory: with temporary_file("""\ # x * 3 == False # x is a variable """, directory=inner_directory): output_file = io.StringIO() eradicate.main(argv=['my_fake_program', '--recursive', directory], standard_out=output_file, standard_error=None) self.assertEqual( '', output_file.getvalue().strip())