Ejemplo n.º 1
0
    def test_program_with_few_lines(self):
        # Print name of this test
        print(inspect.stack()[0][3])

        fake_file_path = "/fake/file/path"

        lines = ["foo", "bar",
                 ""]  # the last empty line ensures that we have a final '\n'

        fake_file = io.StringIO('\n'.join(lines))

        # Create the expectation using the oracle_main
        with patch('monolithic_word_index.open',
                   return_value=fake_file,
                   create=True):
            expected_output = oracle_main(fake_file_path)

        # Create the actual output using the wi_main
        fake_file = io.StringIO('\n'.join(lines))
        with io.StringIO() as buf, redirect_stdout(buf):

            with patch('word_index.open', return_value=fake_file, create=True):
                wi_main(fake_file_path)

            output = buf.getvalue()

        # Assert that the two output matches
        self.assertEqual(output, expected_output, msg="Output does not match")
Ejemplo n.º 2
0
    def test_program_with_sample_file(self):
        # Print name of this test
        print(inspect.stack()[0][3])

        real_file_path = "../test-data/sample.txt"

        expected_output = oracle_main(real_file_path)

        with io.StringIO() as buf, redirect_stdout(buf):
            wi_main(real_file_path)
            output = buf.getvalue()

        # Assert that the two output matches
        self.assertEqual(output, expected_output, msg="Output does not match")
Ejemplo n.º 3
0
    def test_program_with_many_lines(self):
        # Print name of this test
        print(inspect.stack()[0][3])

        fake_file_path = "/fake/file/path"

        lines = []
        # This should appear on output
        for i in range(1, 100):
            lines.append("foo")

        # This should not appear on output
        for i in range(1, 101):
            lines.append("bar")

        lines.append("")

        fake_file = io.StringIO('\n'.join(lines))

        # Create the expectation using the oracle_main
        with patch('monolithic_word_index.open',
                   return_value=fake_file,
                   create=True):
            expected_output = oracle_main(fake_file_path)

        # Create the actual output using the wi_main
        fake_file = io.StringIO('\n'.join(lines))
        with io.StringIO() as buf, redirect_stdout(buf):

            with patch('word_index.open', return_value=fake_file, create=True):
                wi_main(fake_file_path)

            output = buf.getvalue()

        # Assert that the two output matches
        self.assertEqual(output, expected_output, msg="Output does not match")