Esempio n. 1
0
    def test_run_withNoArgumentsForManyTargets(self):
        self._patchArgumentParser(targetProducts=MANY_PRODUCTS,
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults()

        StatMain.run()

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(None)])

        expected = \
            [item for product in MANY_PRODUCTS for item in [call(ALL_PRODUCT_FILES[product]), call().generate()]]
        self.assertCalls(self.statMakefileGenerator, expected)

        expected = \
            [call(makeFile, MAKE_ARGUMENTS, True, True) for makeFile in MANY_MAKE_FILES] * len(MANY_PRODUCT_FILES)
        self.assertCalls(self.runTestPackage, expected)

        expected = {
            makeFile: {
                "Status": "PASSED",
                "Info": ""
            }
            for makeFile in MANY_MAKE_FILES
        }
        expected = {product: expected for product in MANY_PRODUCTS}
        self.assertCalls(self.writeJsonFile,
                         [call(attributes.REPORT_FILENAME, expected)])
Esempio n. 2
0
    def test_run_uponGearBoost(self):
        if sys.version_info >= (3, 0):
            self.skipTest(
                "Multiprocessing can't work in an interactive environment under Python 3+."
            )
        expectedCores = 8
        receivedCores = []

        def spyPool(cores, *args, **kwargs):
            receivedCores.append(cores)
            return Pool(cores, *args, **kwargs)

        self._patchArgumentParser(targetProducts=MANY_PRODUCTS,
                                  userMakefiles=MANY_MAKE_FILES,
                                  processes=expectedCores)
        self._mockParserResults(shallBeVerbose=False)
        self.patch(CUT, Pool.__name__, new=spyPool)

        StatMain.run(['-g'])

        self.assertEqual([expectedCores] * len(MANY_PRODUCTS), receivedCores)

        expected = {
            makeFile: {
                "Status": "PASSED",
                "Info": TEST_INFO_FORMAT.format(MAKE_ARGUMENTS, True, False)
            }
            for makeFile in MANY_MAKE_FILES
        }
        expected = {product: expected for product in MANY_PRODUCTS}
        self.assertCalls(self.writeJsonFile,
                         [call(attributes.REPORT_FILENAME, expected)])
Esempio n. 3
0
    def test_run_withNonStaleConfigurationSameProduct(self):
        self.statConfiguration.return_value.isStale.return_value = False
        self._patchArgumentParser(targetProducts=[DEFAULT_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults()

        StatMain.run()

        self.assertCalls(self.statMakefileGenerator, [])
        expected = [
            call(makeFile, MAKE_ARGUMENTS, True, True)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)
Esempio n. 4
0
    def test_run_withCompileOnlyArguments(self):
        self._patchArgumentParser(targetProducts=[TARGET_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults(shallExecute=False)

        StatMain.run(['-b'])

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(['-b'])])
        expected = [
            call(makeFile, MAKE_ARGUMENTS, False, True)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)
Esempio n. 5
0
    def test_run_withSingleLevelOfCleaning(self):
        self._patchArgumentParser(targetProducts=[TARGET_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults(shallExecute=False, cleaningLevel=1)

        StatMain.run(['-b', '-c'])

        expectedCommandLine = MAKE_ARGUMENTS + [attributes.REBUILD_TARGET]
        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(['-b', '-c'])])
        expected = [
            call(makeFile, expectedCommandLine, False, True)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)
Esempio n. 6
0
    def test_run_uponVisualStudioRequest(self):
        self._patchArgumentParser(targetProducts=[TARGET_PRODUCT],
                                  userMakefiles=[SINGLE_MAKE_FILE])
        self._mockParserResults(MsvsWriter.IDE)

        StatMain.run(['-vs'])

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(['-vs'])])
        self.assertCalls(
            self.statMakefileGenerator,
            [call(ALL_PRODUCT_FILES[TARGET_PRODUCT]),
             call().generate()])
        self.assertCalls(self.runTestPackage, [])
        self.assertCalls(
            self.ideWorkspaceWriter,
            [call(MsvsWriter.IDE, SINGLE_MAKE_FILE),
             call().write()])
Esempio n. 7
0
    def test_run_withException(self):
        self.runTestPackage.side_effect = FAKE_FAILED_RUNS
        self._patchArgumentParser(targetProducts=[TARGET_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults()
        printMock = self.patchBuiltinObject('print')

        try:
            StatMain.run()
        except StatException:
            pass
        else:
            self.fail("The framework shall fire a STAT Exception.")

        expected = [
            call(makeFile, MAKE_ARGUMENTS, True, True)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)

        self.assertCalls(self.remove, [call(attributes.LOGS_DIRECTORY)])
        self.assertCalls(self.mkdir, [
            call(attributes.LOGS_DIRECTORY),
            call(attributes.OUTPUT_DIRECTORY, exist_ok=True)
        ])

        expected = {
            makeFile: {
                "Status": "FAILED",
                "Info": FAKE_EXCEPTION_MESSAGE
            }
            for makeFile in MANY_MAKE_FILES
        }
        self.assertCalls(
            self.writeJsonFile,
            [call(attributes.REPORT_FILENAME, {TARGET_PRODUCT: expected})])

        count = len(MANY_MAKE_FILES)
        expected = [
            call(STAT_OUTPUT_DELIMITER),
            call(STAT_SUMMARY.format(total=count, passed=0, failed=count))
        ]
        self.assertCalls(printMock, expected)
Esempio n. 8
0
    def test_run_withSilentArguments(self):
        self._patchArgumentParser(targetProducts=[TARGET_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults(shallBeVerbose=False)
        printMock = self.patchBuiltinObject('print')

        StatMain.run(['-s'])

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(['-s'])])
        expected = [
            call(makeFile, MAKE_ARGUMENTS, True, False)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)
        count = len(MANY_MAKE_FILES)
        expected = [call(STAT_SILENT_OUTPUT.format(makeFile, 'PASSED')) for makeFile in MANY_MAKE_FILES] + \
                   [call(STAT_OUTPUT_DELIMITER), call(STAT_SUMMARY.format(total=count, passed=count, failed=0))]
        self.assertCalls(printMock, expected)
Esempio n. 9
0
    def test_run_withNonStaleConfigurationAnotherProduct(self):
        self.statConfiguration.return_value.isStale.return_value = False
        self._patchArgumentParser(targetProducts=[TARGET_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults()
        arguments = ['-p', DEFAULT_PRODUCT]

        StatMain.run(arguments)

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(arguments)])
        self.assertCalls(
            self.statMakefileGenerator,
            [call(ALL_PRODUCT_FILES[TARGET_PRODUCT]),
             call().generate()])
        expected = [
            call(makeFile, MAKE_ARGUMENTS, True, True)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)
Esempio n. 10
0
    def test_run_withRedundantArguments(self):
        self._patchArgumentParser(targetProducts=[TARGET_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults(shallExecute=False)
        self.redundantArguments.return_value = ['-run', '--redundant']

        try:
            StatMain.run(['-b'])
        except StatWarning:
            pass
        else:
            self.fail("The framework shall fire a STAT Warning.")

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(['-b'])])
        expected = [
            call(makeFile, MAKE_ARGUMENTS, False, True)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)
Esempio n. 11
0
    def test_run_withAllTargets(self):
        self._patchArgumentParser(targetProducts=MANY_PRODUCTS,
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults()
        self.statConfiguration.return_value.isStale.return_value = False

        StatMain.run(['-a'])

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(['-a'])])

        expected = [
            item for product in MANY_PRODUCTS
            for item in [call(ALL_PRODUCT_FILES[product]),
                         call().generate()]
        ]
        self.assertCalls(self.statMakefileGenerator, expected)

        expected = \
            [call(makeFile, MAKE_ARGUMENTS, True, True) for makeFile in MANY_MAKE_FILES] * len(MANY_PRODUCT_FILES)
        self.assertCalls(self.runTestPackage, expected)
Esempio n. 12
0
    def test_run_withNoArgumentsForSingleTarget(self):
        self._patchArgumentParser(targetProducts=[DEFAULT_PRODUCT],
                                  userMakefiles=MANY_MAKE_FILES)
        self._mockParserResults()

        StatMain.run()

        self.statArgumentParser.assert_has_calls(
            [call(MANY_PRODUCTS, DEFAULT_PRODUCT),
             call().parse(None)])
        self.assertCalls(self.remove, [call(attributes.LOGS_DIRECTORY)])
        self.assertCalls(
            self.mkdir,
            [call('logs'), call('output', exist_ok=True)])
        self.assertCalls(self.open, [])

        expected = [
            call(ALL_PRODUCT_FILES[DEFAULT_PRODUCT]),
            call().generate()
        ]
        self.assertCalls(self.statMakefileGenerator, expected)

        expected = [
            call(makeFile, MAKE_ARGUMENTS, True, True)
            for makeFile in MANY_MAKE_FILES
        ]
        self.assertCalls(self.runTestPackage, expected)

        expected = {
            makeFile: {
                "Status": "PASSED",
                "Info": ""
            }
            for makeFile in MANY_MAKE_FILES
        }
        self.assertCalls(
            self.writeJsonFile,
            [call(attributes.REPORT_FILENAME, {DEFAULT_PRODUCT: expected})])