def test_talosconfig(self):
        # This function stimulates a call to generateTalosConfig in talosconfig.py . It is then tested whether the output generated is correct or not.

        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        test = talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)

        # ensure that the output generated in yaml file is as expected or not.
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])
        self.validate(content['command'],"test/path/to/firefox -profile pathtoprofile -tp pathtotpmanifest -tpchrome -tpmozafterpaint -tpnoisy -rss -tpcycles 1 -tppagecycles 1")
        self.validate(content['child_process'],"plugin-container")
        self.validate(content['process'],"firefox.exe")
        self.validate(content['browser_wait'],5)
        self.validate(content['test_timeout'],1200)
        self.validate(content['browser_log'],"browser_output.txt")
        self.validate(content['browser_path'],"test/path/to/firefox")
        self.validate(content['error_filename'],"pathtoerrorfile")
        self.validate(content['xperf_path'],"C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe")
        self.validate(content['buildid'],20131205075310L)
        self.validate(content['sourcestamp'],"39faf812aaec")
        self.validate(content['repository'],"http://hg.mozilla.org/releases/mozilla-release")
        self.validate(content['title'],"qm-pxp01")
        self.validate(content['testname'],"tp5n")
        self.validate(content['xperf_providers'],['PROC_THREAD', 'LOADER', 'HARD_FAULTS', 'FILENAME', 'FILE_IO', 'FILE_IO_INIT'])
        self.validate(content['xperf_user_providers'],['Mozilla Generic Provider', 'Microsoft-Windows-TCPIP'])
        self.validate(content['xperf_stackwalk'],['FileCreate', 'FileRead', 'FileWrite', 'FileFlush', 'FileClose'])
        self.validate(content['processID'],"None")
        self.validate(content['approot'],"test/path/to")
    def test_talosconfig(self):
        # This function stimulates a call to generateTalosConfig in talosconfig.py . It is then tested whether the output generated is correct or not.

        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        test = talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)

        # ensure that the output generated in yaml file is as expected or not.
        yaml = YAML()
        content = yaml.read(browser_config["bcontroller_config"])
        self.validate(
            content["command"],
            "test/path/to/firefox -profile pathtoprofile -tp pathtotpmanifest -tpchrome -tpmozafterpaint -tpnoisy -rss -tpcycles 1 -tppagecycles 1",
        )
        self.validate(content["child_process"], "plugin-container")
        self.validate(content["process"], "firefox.exe")
        self.validate(content["browser_wait"], 5)
        self.validate(content["test_timeout"], 1200)
        self.validate(content["browser_log"], "browser_output.txt")
        self.validate(content["browser_path"], "test/path/to/firefox")
        self.validate(content["error_filename"], "pathtoerrorfile")
        self.validate(content["xperf_path"], "C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe")
        self.validate(content["buildid"], 20131205075310L)
        self.validate(content["sourcestamp"], "39faf812aaec")
        self.validate(content["repository"], "http://hg.mozilla.org/releases/mozilla-release")
        self.validate(content["title"], "qm-pxp01")
        self.validate(content["testname"], "tp5n")
        self.validate(
            content["xperf_providers"], ["PROC_THREAD", "LOADER", "HARD_FAULTS", "FILENAME", "FILE_IO", "FILE_IO_INIT"]
        )
        self.validate(content["xperf_user_providers"], ["Mozilla Generic Provider", "Microsoft-Windows-TCPIP"])
        self.validate(content["xperf_stackwalk"], ["FileCreate", "FileRead", "FileWrite", "FileFlush", "FileClose"])
        self.validate(content["processID"], "None")
        self.validate(content["approot"], "test/path/to")
    def test_talosconfig(self):
        # This function stimulates a call to generateTalosConfig in talosconfig.py . It is then tested whether the output generated is correct or not.

        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        test = talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)

        # ensure that the output generated in yaml file is as expected or not.
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])
        self.validate(content['command'],"test/path/to/firefox -profile pathtoprofile -tp pathtotpmanifest -tpchrome -tpmozafterpaint -tpnoisy -rss -tpcycles 1 -tppagecycles 1")
        self.validate(content['child_process'],"firefox-webcontent")
        self.validate(content['process'],"firefox.exe")
        self.validate(content['browser_wait'],5)
        self.validate(content['test_timeout'],1200)
        self.validate(content['browser_log'],"browser_output.txt")
        self.validate(content['browser_path'],"test/path/to/firefox")
        self.validate(content['error_filename'],"pathtoerrorfile")
        self.validate(content['xperf_path'],"C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe")
        self.validate(content['buildid'],20131205075310L)
        self.validate(content['sourcestamp'],"39faf812aaec")
        self.validate(content['repository'],"http://hg.mozilla.org/releases/mozilla-release")
        self.validate(content['title'],"qm-pxp01")
        self.validate(content['testname'],"tp5n")
        self.validate(content['xperf_providers'],['PROC_THREAD', 'LOADER', 'HARD_FAULTS', 'FILENAME', 'FILE_IO', 'FILE_IO_INIT'])
        self.validate(content['xperf_user_providers'],['Mozilla Generic Provider', 'Microsoft-Windows-TCPIP'])
        self.validate(content['xperf_stackwalk'],['FileCreate', 'FileRead', 'FileWrite', 'FileFlush', 'FileClose'])
        self.validate(content['processID'],"None")
        self.validate(content['approot'],"test/path/to")
    def test_errors(self):
        # Tests if errors are correctly raised.

        # Testing that error is correctly raised or not if xperf_path is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del browser_config_copy['xperf_path']
        talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])

        with self.assertRaises(KeyError):
            self.validate(content['xperf_path'],
                          "C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe")

        # Test to see if keyerror is raised or not for calling testname when xperf_path is missing
        with self.assertRaises(KeyError):
            self.validate(content['testname'], "tp5n")

        # Testing that error is correctly raised or not if xperf_providers is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del test_config_copy['xperf_providers']
        talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])

        # Checking keyerror when calling xperf_providers
        with self.assertRaises(KeyError):
            self.validate(content['xperf_providers'], ['PROC_THREAD', 'LOADER', 'HARD_FAULTS',
                                                       'FILENAME', 'FILE_IO', 'FILE_IO_INIT'])

        # Checking keyerror when calling xperf_user_providers when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['xperf_user_providers'],
                          ['Mozilla Generic Provider', 'Microsoft-Windows-TCPIP'])

        # Checking keyerror when calling xperf_stackwalk when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['xperf_stackwalk'],
                          ['FileCreate', 'FileRead', 'FileWrite', 'FileFlush', 'FileClose'])

        # Checking keyerror when calling processID when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['processID'], "None")

        # Checking keyerror when calling approot when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['approot'], "test/path/to")
    def test_errors(self):
        # Tests if errors are correctly raised.

        # Testing that error is correctly raised or not if xperf_path is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del browser_config_copy["xperf_path"]
        talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config["bcontroller_config"])

        with self.assertRaises(KeyError):
            self.validate(content["xperf_path"], "C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe")

        # Test to see if keyerror is raised or not for calling testname when xperf_path is missing
        with self.assertRaises(KeyError):
            self.validate(content["testname"], "tp5n")

        # Testing that error is correctly raised or not if xperf_providers is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del test_config_copy["xperf_providers"]
        talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config["bcontroller_config"])

        # Test to see if keyerror is raised or not when calling xperf_providers
        with self.assertRaises(KeyError):
            self.validate(
                content["xperf_providers"],
                ["PROC_THREAD", "LOADER", "HARD_FAULTS", "FILENAME", "FILE_IO", "FILE_IO_INIT"],
            )

        # Test to see if keyerror is raised or not when calling xperf_user_providers when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content["xperf_user_providers"], ["Mozilla Generic Provider", "Microsoft-Windows-TCPIP"])

        # Test to see if keyerror is raised or not when calling xperf_stackwalk when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content["xperf_stackwalk"], ["FileCreate", "FileRead", "FileWrite", "FileFlush", "FileClose"])

        # Test to see if keyerror is raised or not when calling processID when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content["processID"], "None")

        # Test to see if keyerror is raised or not when calling approot when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content["approot"], "test/path/to")
    def test_cli(self):
        """
        Tests PerfConfigurator command line interface.

        This test simulates a call to the PerfConfigurator class from the
        command line interface with a sample of typical options that are
        available to the user.
        It is then tested if the given variables are correctly written into
        options, self.config and into a generated yaml file as output.

        For an explanation of the options given, see PerfConfigurator.py

        """

        example = PerfConfigurator()

        # parse the standard commands
        outfile = tempfile.mktemp(suffix='.yaml')
        options, args = example.parse_args([
            '--activeTests', 'ts', '--develop', '-e', ffox_path, '-o', outfile
        ])
        self.assertTrue(os.path.exists(outfile))

        # ensure that the options appropriately get set
        self.assertEqual(bool(args), False)  # no arguments
        self.assertEqual(options.develop, True)
        self.assertEqual(options.activeTests, 'ts')
        self.assertEqual(options.browser_path, ffox_path)

        # ensure that the configuration appropriately gets updated
        self.assertEqual(example.config['develop'], True)
        self.assertEqual(example.config['browser_path'], ffox_path)
        self.assertEqual(example.config['tests'][0]['name'], 'ts')

        # ensure that the yaml information are accurate with respect to the data given
        yaml = YAML()
        content = yaml.read(outfile)
        self.assertEqual(content['browser_path'], ffox_path)
        self.assertEqual(content['tests'][0]['name'], 'ts')
        self.assertEqual(content['develop'], True)

        # cleanup
        os.remove(outfile)
    def test_errors(self):
        # Tests if errors are correctly raised.

        # Testing that error is correctly raised or not if xperf_path is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del browser_config_copy['xperf_path']
        talosconfig.generateTalosConfig(command_args, browser_config_copy,
                                        test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])

        with self.assertRaises(KeyError):
            self.validate(
                content['xperf_path'],
                "C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe"
            )

        # Test to see if keyerror is raised or not for calling testname when xperf_path is missing
        with self.assertRaises(KeyError):
            self.validate(content['testname'], "tp5n")

        # Testing that error is correctly raised or not if xperf_providers is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del test_config_copy['xperf_providers']
        talosconfig.generateTalosConfig(command_args, browser_config_copy,
                                        test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])

        # Test to see if keyerror is raised or not when calling xperf_providers
        with self.assertRaises(KeyError):
            self.validate(content['xperf_providers'], [
                'PROC_THREAD', 'LOADER', 'HARD_FAULTS', 'FILENAME', 'FILE_IO',
                'FILE_IO_INIT'
            ])

        # Test to see if keyerror is raised or not when calling xperf_user_providers when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(
                content['xperf_user_providers'],
                ['Mozilla Generic Provider', 'Microsoft-Windows-TCPIP'])

        # Test to see if keyerror is raised or not when calling xperf_stackwalk when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['xperf_stackwalk'], [
                'FileCreate', 'FileRead', 'FileWrite', 'FileFlush', 'FileClose'
            ])

        # Test to see if keyerror is raised or not when calling processID when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['processID'], "None")

        # Test to see if keyerror is raised or not when calling approot when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['approot'], "test/path/to")