def test_valid_string_alternating_capitalized_letters(self, mock_input): # with unittest.mock.patch('volumeOfCube.retrieve_input', return_value=-1): capturedOutput = io.StringIO() # Create StringIO object sys.stdout = capturedOutput # and redirect stdout. palindrome.main() # Call function. sys.stdout = sys.__stdout__ # Reset redirect. expected = ['True', ''] actual = capturedOutput.getvalue().split('\n') self.assertEqual(actual, expected)
def main(): """Find longest subpalindrome in War and Peace.""" with open('war_and_peace_gutenberg.txt', 'r') as f: text = f.read() assert palindrome.main(text) == 'ton did not' return True
def test_valid_string_alternating_capitalized_letters(monkeypatch): test_string = StringIO('tAcOcAt\n') monkeypatch.setattr('sys.stdin', test_string) assert palindrome.main() == True
def test_valid_string(monkeypatch): test_string = StringIO('tacocat\n') monkeypatch.setattr('sys.stdin', test_string) assert palindrome.main() == True
def test_empty_string(monkeypatch): test_string = StringIO('\n') monkeypatch.setattr('sys.stdin', test_string) assert palindrome.main() == True
def test_bad_string(monkeypatch): test_string = StringIO('Thisisanactivity\n') monkeypatch.setattr('sys.stdin', test_string) assert palindrome.main() == False
def main_op(self, tst_str, mock_stdout): with mock.patch('builtins.input', side_effect=tst_str): palindrome.main() return mock_stdout.getvalue()
def test_input_two(self, stdout): main() self.assertEqual(stdout.getvalue(), 'False\n')
def test_input_one(self, stdout): main() self.assertEqual(stdout.getvalue(), 'True\n')