Esempio n. 1
0
def main():
    """
    Main entry point for the command-line tool.
    """
    args_dict = parse_args(sys.argv)
    command = args_dict.get('command')

    if command == 'init':
        create_default_suite(*args_dict.get('test_suite_paths'))

    elif command == 'dev':

        # Arg validation guarantees that there is exactly 1 path
        test_suite_path = args_dict.get('test_suite_paths')[0]

        # Build a dev-mode runner using a factory
        factory = SuiteDevRunnerFactory()
        suite_dev_runner = factory.build_runner(test_suite_path)

        # Run in dev mode (serve pages until user terminates)
        suite_dev_runner.run()

    elif command == 'run':

        # Configure a test suite runner
        factory = SuiteRunnerFactory()
        suite_runner, browser_list = \
            factory.build_runner(
                args_dict.get('test_suite_paths'),
                args_dict.get('browser_names'),
                args_dict.get('xunit_report'),
                args_dict.get('coverage_xml'),
                args_dict.get('coverage_html'),
                args_dict.get('timeout_sec')
            )

        try:
            # Generate the reports and write test results
            all_passed = generate_reports(suite_runner)

        finally:

            # Quit out of the browsers we created
            for browser in browser_list:
                browser.quit()

        # If any test failed, exit with non-zero status code
        if not all_passed:
            sys.exit(1)

    # Shouldn't get here because we validate the args,
    # but it never hurts to check.
    else:
        raise SystemExit('Invalid command.')
Esempio n. 2
0
    def setUp(self):

        # Call superclass implementation to create the workspace
        super(SuiteDevRunnerFactoryTest, self).setUp()

        # Create mock instances to be returned by the constructors
        # of each mock class.
        self.mock_desc = mock.MagicMock(SuiteDescription)
        self.mock_renderer = mock.MagicMock(SuiteRenderer)
        self.mock_server = mock.MagicMock(SuitePageServer)
        self.mock_runner = mock.MagicMock(SuiteDevRunner)

        # Create mocks for each class that the factory will instantiate
        self.mock_desc_class = mock.MagicMock(return_value=self.mock_desc)
        self.mock_renderer_class = mock.MagicMock(return_value=self.mock_renderer)
        self.mock_server_class = mock.MagicMock(return_value=self.mock_server)
        self.mock_runner_class = mock.MagicMock(return_value=self.mock_runner)

        # Create the factory
        self.factory = SuiteDevRunnerFactory(
            desc_class=self.mock_desc_class,
            renderer_class=self.mock_renderer_class,
            server_class=self.mock_server_class)
Esempio n. 3
0
class SuiteDevRunnerFactoryTest(TempWorkspaceTestCase):

    def setUp(self):

        # Call superclass implementation to create the workspace
        super(SuiteDevRunnerFactoryTest, self).setUp()

        # Create mock instances to be returned by the constructors
        # of each mock class.
        self.mock_desc = mock.MagicMock(SuiteDescription)
        self.mock_renderer = mock.MagicMock(SuiteRenderer)
        self.mock_server = mock.MagicMock(SuitePageServer)
        self.mock_runner = mock.MagicMock(SuiteDevRunner)

        # Create mocks for each class that the factory will instantiate
        self.mock_desc_class = mock.MagicMock(return_value=self.mock_desc)
        self.mock_renderer_class = mock.MagicMock(return_value=self.mock_renderer)
        self.mock_server_class = mock.MagicMock(return_value=self.mock_server)
        self.mock_runner_class = mock.MagicMock(return_value=self.mock_runner)

        # Create the factory
        self.factory = SuiteDevRunnerFactory(
            desc_class=self.mock_desc_class,
            renderer_class=self.mock_renderer_class,
            server_class=self.mock_server_class)

    def test_build_runner(self):

        # Create fake suite description file
        suite_path = 'test_suite.yml'
        with open(suite_path, 'w') as suite_file:
            suite_file.write('test file')

        # Build the runner instance
        runner = self.factory.build_runner('test_suite.yml', port=42)

        # Should get a runner
        self.assertTrue(isinstance(runner, SuiteDevRunner))

        # Retrieve the arguments used to initialize the suite description
        call_args_list = self.mock_desc_class.call_args_list
        self.assertEqual(len(call_args_list), 1)
        args, _ = call_args_list[0]
        file_handle = args[0]
        root_dir = args[1]

        # Expect that the file handle points to the right file
        self.assertEqual(suite_path, file_handle.name)

        # Root directory should be the location of the suite file
        self.assertEqual(os.path.realpath(root_dir),
                         os.path.realpath(self.temp_dir))

        # Expect that the renderer is configured to render the
        # dev mode version of the test runner page
        self.mock_renderer_class.assert_called_once_with(dev_mode=True)

        # Expect that the server was configured with the renderer
        # and suite description
        self.mock_server_class.assert_called_with([self.mock_desc],
                                                  self.mock_renderer,
                                                  jscover_path=None, port=42)