예제 #1
0
 def test_normal_values_with_double_space(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.
     wordCount.main()  # Call function.
     sys.stdout = sys.__stdout__  # Reset redirect.
     expected = ['4', '']
     actual = capturedOutput.getvalue().split('\n')
     self.assertEqual(actual, expected)
def test_valid_string(monkeypatch):
    test_string = StringIO('This  is  an  activity\n')
    monkeypatch.setattr('sys.stdin', test_string)
    assert wordCount.main() == 4
def test_single_word(monkeypatch):
    test_string = StringIO('thisisanactivity\n')
    monkeypatch.setattr('sys.stdin', test_string)
    assert wordCount.main() == 1
def test_empty_string(monkeypatch):
    test_string = StringIO('\n')
    monkeypatch.setattr('sys.stdin', test_string)
    assert wordCount.main() == 0