Exemple #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)])
Exemple #2
0
    def test_add_file(self):
        parentTokens = ['PARENT-TOKEN-A', 'PARENT-TOKEN-B']

        self.writer.addFile('file-path', parentTokens)
        for writer, parent in zip(self.writer.writers, parentTokens):
            self.assertCalls(
                writer,
                [call(self.contents, ()),
                 call().addFile('file-path', parent)])
Exemple #3
0
    def test_create_root_token(self):
        self.writerA.return_value.createRootToken.return_value = 'TOKEN-A'
        self.writerB.return_value.createRootToken.return_value = 'TOKEN-B'

        tokens = self.writer.createRootToken()
        self.assertEqual(['TOKEN-A', 'TOKEN-B'], tokens)
        for writer in self.writer.writers:
            self.assertCalls(
                writer,
                [call(self.contents,
                      ()), call().createRootToken()])
Exemple #4
0
    def test_create_directory_token(self):
        parentTokens = ['PARENT-TOKEN-A', 'PARENT-TOKEN-B']
        self.writerA.return_value.createDirectoryToken.return_value = 'DIR-TOKEN-A'
        self.writerB.return_value.createDirectoryToken.return_value = 'DIR-TOKEN-B'

        tokens = self.writer.createDirectoryToken('directory', parentTokens)
        self.assertEqual(['DIR-TOKEN-A', 'DIR-TOKEN-B'], tokens)
        for writer, parent in zip(self.writer.writers, parentTokens):
            self.assertCalls(writer, [
                call(self.contents, ()),
                call().createDirectoryToken('directory', parent)
            ])
Exemple #5
0
    def test_runTestPackage_compileOnly(self):
        results = runTestPackage(SINGLE_MAKE_FILE,
                                 MAKE_ARGUMENTS,
                                 shallRun=False,
                                 shallBeVerbose=True)

        expected = [
            call(SINGLE_MAKE_FILE, MAKE_ARGUMENTS, True),
            call().compile()
        ]
        self.assertCalls(self.testsRunner, expected)
        self.assertEqual((SINGLE_MAKE_FILE, 'PASSED', ''), results)
Exemple #6
0
    def test_write(self):
        writer = self.writer

        writer.write()

        self.assertCalls(self.ideXmlWriter_write, [call()])
        expected = [
            call(self.makefileProject, self.tools,
                 MsvsLegacyWriter._PROJECT_GUID,
                 "vs_" + self.makefileProject.name + ".vcxproj"),
            call().write()
        ]
        self.assertCalls(self.msvsSolutionWriter, expected)
Exemple #7
0
    def test_silent(self):
        runner = createRunner(isVerbose=False)
        runner.compile()
        runner.run()

        expectedEnv = dict(TEST_ENVIRONMENT_MOCK,
                           STAT_NAMESPACE=self.makefile.name)
        execPath = os.path.join(attributes.OUTPUT_DIRECTORY, TEST_PACKAGE_NAME,
                                'bin', self.makefile[StatMakefile.EXEC])
        expected = [
            call(self.expectedCommand, beSilent=True, env=expectedEnv),
            call(execPath, beSilent=True)
        ]
        self.assertCalls(self.execute, expected)
Exemple #8
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)
Exemple #9
0
    def test_run(self):
        runner = createRunner()
        runner.run()

        execPath = os.path.join(attributes.OUTPUT_DIRECTORY, TEST_PACKAGE_NAME,
                                'bin', self.makefile[StatMakefile.EXEC])
        self.assertCalls(self.execute, [call(execPath, beSilent=False)])
Exemple #10
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)
Exemple #11
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)])
Exemple #12
0
    def test_retrieveMsvsOnWindows(self):
        self.patchObject(platform, platform.system.__name__, return_value="Windows")

        crawler = BuildToolsCrawler()

        self.assertEqual(self.msvsTools.return_value, crawler.retrieveMsvs())
        self.msvsTools.assert_has_calls([call(self.configuration)])
Exemple #13
0
    def test_compile(self):
        runner = createRunner()
        runner.compile()

        expectedEnv = dict(TEST_ENVIRONMENT_MOCK,
                           STAT_NAMESPACE=self.makefile.name)
        self.assertCalls(
            self.execute,
            [call(self.expectedCommand, beSilent=False, env=expectedEnv)])
Exemple #14
0
    def test_write(self):
        self.writer.write()

        self.assertCalls(self.mkdir,
                         [call(attributes.IDE_DIRECTORY, exist_ok=True)])
        tokens, files = self.__getTreeItems(self.contents.tree, ROOT_TOKEN)
        self.assertSameItems(tokens, self.testWriter.tokens)
        self.assertSameItems(files, self.testWriter.files)
        self.assertEqual(TEST_IDE_OUTPUT + str(tokens), self.testWriter.output)
Exemple #15
0
    def test_composeElement(self):
        elementMock = Mock(spec=Element)
        self.mdomDocument.return_value.createElement.return_value = elementMock
        elementAttributes = {
            'first': 1111,
            'second': 2222,
            'another': 'some text',
            'boolean': True
        }

        element = self.writer.composeElement("nameOfElement",
                                             **elementAttributes)
        self.assertEqual(elementMock, element)
        self.mdomDocument.assert_has_calls(
            [call(), call().createElement("nameOfElement")])
        expected = [
            call.setAttribute(attribute, value)
            for attribute, value in elementAttributes.items()
        ]
        self.assertCalls(elementMock, expected, ordered=False)
Exemple #16
0
    def test_runTestPackage_withTestException(self):
        exception = "Fake exception to test error-handling"

        def fakeRunMethod():
            raise TestsRunnerException(exception)

        self.testsRunner.return_value.run.side_effect = fakeRunMethod

        results = runTestPackage(SINGLE_MAKE_FILE,
                                 MAKE_ARGUMENTS,
                                 shallRun=True,
                                 shallBeVerbose=True)

        expected = [
            call(SINGLE_MAKE_FILE, MAKE_ARGUMENTS, True),
            call().compile(),
            call().run(),
            call().writeLog(exception)
        ]
        self.assertCalls(self.testsRunner, expected)
        self.assertEqual((SINGLE_MAKE_FILE, 'FAILED', exception), results)
Exemple #17
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)
Exemple #18
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)
Exemple #19
0
    def test_runTestPackage_withAbnormalTestException(self):
        exception = "This is abnormal exception emulation"

        def fakeRunMethod():
            raise Exception(exception)

        self.testsRunner.return_value.run.side_effect = fakeRunMethod

        results = runTestPackage(SINGLE_MAKE_FILE,
                                 MAKE_ARGUMENTS,
                                 shallRun=True,
                                 shallBeVerbose=True)

        expected = [
            call(SINGLE_MAKE_FILE, MAKE_ARGUMENTS, True),
            call().compile(),
            call().run(),
            call().writeLog(exception)
        ]
        self.assertCalls(self.testsRunner, expected)
        self.assertEqual((SINGLE_MAKE_FILE, 'CRASHED', exception), results)
Exemple #20
0
    def test_write(self):
        FILENAME_MOCK = 'example_filename.ext'
        self.writer._filename = FILENAME_MOCK
        self.osOpen = self.patchOpen()

        self.writer.write()
        expected = [
            call(self.__getTargetPath(FILENAME_MOCK), 'w'),
            call().flush(),
            call().close()
        ]
        self.assertCalls(self.osOpen, expected)
        expected = [
            call(),
            call(self.osOpen.return_value,
                 indent="",
                 addindent="\t",
                 newl="\n",
                 encoding="utf-8")
        ]
        self.assertCalls(self.mdomDocument, expected)
Exemple #21
0
    def test_composeElement_withContextValue(self):
        elementMock = Mock(spec=Element)
        self.mdomDocument.return_value.createElement.return_value = elementMock
        self.mdomDocument.return_value.createTextNode.side_effect = lambda x: "value is {0}".format(
            x)
        elementAttributes = {
            'first-attribute': 101010,
            'second-one': 'some text'
        }

        element = self.writer.composeElement("nameOfElement",
                                             context=17,
                                             **elementAttributes)
        self.assertEqual(elementMock, element)
        self.mdomDocument.assert_has_calls(
            [call(), call().createElement("nameOfElement")])
        expected = [call.appendChild("value is {0}".format(17))]
        expected.extend([
            call.setAttribute(attribute, elementAttributes[attribute])
            for attribute in elementAttributes
        ])
        self.assertCalls(elementMock, expected, ordered=False)
Exemple #22
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)
Exemple #23
0
    def test_composeElement_withContextOfElements(self):
        elements = [Mock(spec=Element) for _dummy in range(4)]
        self.mdomDocument.return_value.createElement.side_effect = elements
        self.mdomDocument.return_value.createTextNode.side_effect = lambda x: "value is {0}".format(
            x)
        elementAttributes = {
            'the-attribute': 'the attribute value',
            'another-one': 'the text of the another one'
        }
        contextElements = {
            'elementA': 'the A text',
            'elementB': 57,
            'elementC': 'the C text'
        }

        element = self.writer.composeElement("nameOfElement",
                                             context=contextElements,
                                             **elementAttributes)

        self.assertEqual(elements[0], element)
        expected = [call(), call().createElement("nameOfElement")]
        expected.extend(
            [call().createElement(name) for name in contextElements])
        self.mdomDocument.assert_has_calls(expected, any_order=True)

        expected = [
            call.setAttribute(attribute, elementAttributes[attribute])
            for attribute in elementAttributes
        ]
        expected.extend([call.appendChild(child) for child in elements[1:]])
        self.assertCalls(element, expected, ordered=False)

        for element, contents in zip(elements[1:], contextElements):
            expected = [
                call.appendChild("value is {0}".format(
                    contextElements[contents]))
            ]
            self.assertCalls(element, expected, ordered=False)
Exemple #24
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)
Exemple #25
0
    def test_writeLog(self):
        executeResults = [(0, ['compile-1', 'compile-2']),
                          (0, ['run-1', 'run-2', 'run-3'])]
        expectedPrintOut = [
            line for results in executeResults for line in results[1]
        ]
        exceptionExtraInfo = "ERROR: Some extra information"
        self.execute.side_effect = executeResults
        runner = createRunner()
        runner.compile()
        runner.run()
        openMock = self.patchOpen()

        runner.writeLog(exceptionExtraInfo)

        expected = [
            call('/'.join([attributes.LOGS_DIRECTORY, TEST_LOGFILE_NAME]),
                 'a'),
            call().__enter__(),
            call().writelines(expectedPrintOut),
            call().write(exceptionExtraInfo),
            call().__exit__(None, None, None)
        ]
        self.assertCalls(openMock, expected)
Exemple #26
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})])
Exemple #27
0
    def test_runTestPackage_withExceptionUponInitialization(self):
        exception = Exception(
            "This is an emulation of exception upon makefile processing")

        def initFakeRunner(*args, **kwargs):
            raise exception

        self.testsRunner.side_effect = initFakeRunner

        results = runTestPackage(SINGLE_MAKE_FILE,
                                 MAKE_ARGUMENTS,
                                 shallRun=True,
                                 shallBeVerbose=True)

        expected = [call(SINGLE_MAKE_FILE, MAKE_ARGUMENTS, True)]
        self.assertCalls(self.testsRunner, expected)
        self.assertEqual(
            (SINGLE_MAKE_FILE, 'CRASHED',
             MAKEFILE_CORRUPTION.format(filename=SINGLE_MAKE_FILE,
                                        exception=str(exception))), results)
Exemple #28
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)
Exemple #29
0
 def test___init__basics(self):
     config = StatConfiguration()
     self.assertEqual(attributes.VERSION, config['TOOL_VERSION'])
     self.assertCalls(self.statMakefile, [call(attributes.CONFIG_FILENAME)])
     self.assertEqual("Hello universe!", config['TEST_VARIABLE'])
     self.assertEqual(2008, config.getInt('MSVS_VERSION', 0))
     self.assertCalls(self.isFile, [
         call(
             os.path.join(attributes.PRODUCT_DIRECTORY,
                          attributes.IGNORE_FILENAME)),
         call(attributes.CONFIG_FILENAME),
         call(attributes.AUTO_GENERATED_MAKEFILE)
     ])
     self.assertCalls(self.statMakefile, [call(attributes.CONFIG_FILENAME)])
     self.assertCalls(self.readTextFileAtOnce,
                      [call(attributes.AUTO_GENERATED_MAKEFILE)])
Exemple #30
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()])