def test_isStaleUponUserConfigurationChange(self): autoGeneratedFile = TEST_CONTENTS.format(attributes.VERSION, CONFIG_FILE_TIME - 0.1, VALID_PRODUCT) self.readTextFileAtOnce.return_value = autoGeneratedFile config = StatConfiguration() self.assertTrue(config.isStale())
def test_defaultProductInvalidSpecified(self): autoGeneratedFile = TEST_CONTENTS.format(attributes.VERSION, CONFIG_FILE_TIME, 'some_invalid_product') self.readTextFileAtOnce.return_value = autoGeneratedFile config = StatConfiguration() self.assertIsNone(config.defaultProduct) self.assertTrue(config.isStale())
def test_isStaleUponAutoWithoutConfigVersion(self): newContents = (TEST_CONTENTS[:]).replace('CONFIG_VERSION', 'SOME_OTHER_FIELD') autoGeneratedFile = newContents.format(attributes.VERSION, CONFIG_FILE_TIME, VALID_PRODUCT) self.readTextFileAtOnce.return_value = autoGeneratedFile config = StatConfiguration() self.assertTrue(config.isStale())
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)])
def test___init__basics(self): config = StatConfiguration() self.assertEqual(attributes.VERSION, config['TOOL_VERSION']) self.assertEqual(toPosixPath(attributes.OUTPUT_DIRECTORY), toPosixPath(config['OUTPUT_DIR'])) self.assertEqual(toPosixPath(os.path.relpath(attributes.TOOL_PATH)), toPosixPath(config['STAT_ROOT'])) self.assertEqual(toPosixPath(attributes.DUMMIES_DIRECTORY), toPosixPath(config['DUMMIES_DIR']))
def test_generate(self): config = StatConfiguration() makFile = attributes.AUTO_GENERATED_MAKEFILE generator = StatMakefileGenerator(productMakefile=TEST_PRODUCT_FILE) generator.generate() self.assertTrue(os.path.isfile(makFile)) self.parser = StatMakefile(makFile) for parameter in iter(config): self.assertEqual(config[parameter], self.parser[parameter]) self.assertEqual(TEST_PRODUCT_NAME, self.parser[StatMakefile.NAME]) self.assertEqual(TEST_PRODUCT_EXEC, self.parser[StatMakefile.EXEC]) self.assertEqual(platform.system(), self.parser[StatMakefile.OS]) self.__verifyProductMakefileIsIncluded() self.__verifyToolsMakefileIsIncluded() os.remove(makFile)
def __constructVariablesInitialization(self): def _formatAssignment(_variable, _value): return '{0} = {1}'.format(_variable, _value) def _getValues(*_valueSets): return [ _formatAssignment(_key, _values[_key]) for _values in _valueSets for _key in iter(_values) ] values = [ _formatAssignment(StatMakefile.OS, platform.system()), _formatAssignment(StatMakefile.NAME, self.__targetName), _formatAssignment(StatMakefile.EXEC, nameExecutable(self.__targetName)) ] values += _getValues(StatConfiguration(), BuildToolsCrawler().getBuildAttributes()) return '\n'.join(values)
def __init__(self): self.__config = StatConfiguration() self.__parser = StatArgumentParser(self.__config.products, self.__config.defaultProduct) self.__makeArguments = ['COPY_HEADERS="TRUE"'] self.__report = StatReport()
class StatMain(object): @staticmethod def run(manualArguments=None): """ :param manualArguments: if specified, used instead of system command-line arguments """ main = StatMain() main._run(manualArguments) def __init__(self): self.__config = StatConfiguration() self.__parser = StatArgumentParser(self.__config.products, self.__config.defaultProduct) self.__makeArguments = ['COPY_HEADERS="TRUE"'] self.__report = StatReport() def _run(self, manualArguments): self.__parser.parse(manualArguments) self.adjustCommandLineWithCleaningLevel() if self.__parser.ide is not None: self.__createIdeWorkspace() else: self.__runTests() if self.__parser.redundant: raise StatWarning( 'WARNING: The arguments {0} are redundant!'.format( self.__parser.redundant)) def adjustCommandLineWithCleaningLevel(self): cleaningLevel = self.__parser.getRequestedCleaningLevel() # self.__makeArguments.append("--debug=b") if cleaningLevel > 0: if cleaningLevel > 1: self.__makeArguments.append(attributes.CLEAN_TARGET) self.__makeArguments.append(attributes.REBUILD_TARGET) def __runTests(self): prepareOutputDirectories() for target in self.__parser.targetProducts: self.__runTestsOnTarget(target) self.__report.write() print(STAT_OUTPUT_DELIMITER) print( STAT_SUMMARY.format(total=self.__report.total, passed=self.__report.passed, failed=self.__report.failed)) if self.__report.failed: raise StatException('The following packages failed:\n\t{0}'.format( '\n\t'.join(self.__report.failedList))) def __runTestsOnTarget(self, target): if self.__parser.processes: self.__runTestsOnTargetInParallel(target) else: self.__runTestsOnTargetInSerial(target) def __runTestsOnTargetInSerial(self, target): self.__prepareTarget(target) for makefile in self.__parser.makeFiles: result = runTestPackage(makefile, self.__makeArguments, self.__parser.shallRun(), self.__parser.shallBeVerbose()) self.__log(*result) def __runTestsOnTargetInParallel(self, target): def handleResult(result): self.__log(*result) self.__prepareTarget(target) pool = Pool(self.__parser.processes) for makefile in self.__parser.makeFiles: args = (makefile, self.__makeArguments, self.__parser.shallRun(), self.__parser.shallBeVerbose()) pool.apply_async(runTestPackage, args, callback=handleResult) pool.close() pool.join() def __createIdeWorkspace(self): self.__prepareTarget(self.__parser.targetProducts[0]) writer = IdeWorkspaceWriter(self.__parser.ide, self.__parser.makeFiles[0]) writer.write() def __prepareTarget(self, name): self.__report.logTarget(name) if self.__config.isStale( ) or self.__parser.targetProducts != [self.__config.defaultProduct]: targetMakefile = StatMakefileGenerator(name + ".mak") targetMakefile.generate() def __log(self, makefile, status, info): self.__report[makefile] = status, info if not self.__parser.shallBeVerbose(): print(STAT_SILENT_OUTPUT.format(makefile, status))
def test_defaultProductExplicitlySpecified(self): config = StatConfiguration() self.assertEqual(VALID_PRODUCT, config.defaultProduct) self.assertFalse(config.isStale())
def test_defaultProduct(self): config = StatConfiguration() self.assertEqual(None, config.defaultProduct) self.assertTrue(config.isStale())
def test_products(self): config = StatConfiguration() expected = ['product', 'product_derived'] self.assertSameItems(expected, config.products)
def test__new__isSingleton(self): self.assertEqual(self.config, StatConfiguration())
def setUp(self): self.setupCommon() self.config = StatConfiguration()
def tearDown(self): StatConfiguration.clear()
def __init__(self): self.__msvsTools = MsvsTools(StatConfiguration()) if platform.system() == "Windows" else None self.__tools = [tools for tools in (self.__msvsTools,) if tools]