Пример #1
0
    def test_run_timeout(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            project_id = 10868464
            repository_path = directory
            rawattributes = copy.deepcopy(self.rawattributes)
            for attribute in rawattributes:
                if 'architecture' in attribute['name']:
                    attribute['options']['timeout'] = '1S'  # Sabotage
            expected = (0, {'architecture': None})

            # Act
            attributes = Attributes(
                rawattributes,
                database=Database(self.rawsettings),
                keystring='a',
                goptions=self.rawgoptions
            )
            try:
                attributes.database.connect()
                actual = attributes.run(project_id, repository_path)

                # Assert
                self.assertEqual(expected, actual)
            finally:
                attributes.database.disconnect()
    def test_run_timeout(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            project_id = 10868464
            repository_path = directory
            rawattributes = copy.deepcopy(self.rawattributes)
            for attribute in rawattributes:
                if 'architecture' in attribute['name']:
                    attribute['options']['timeout'] = '1S'  # Sabotage
            expected = (0, {'architecture': None})

            # Act
            attributes = Attributes(
                rawattributes,
                database=Database(self.rawsettings),
                keystring='a',
                goptions=self.rawgoptions
            )
            try:
                attributes.database.connect()
                actual = attributes.run(project_id, repository_path)

                # Assert
                self.assertEqual(expected, actual)
            finally:
                attributes.database.disconnect()
    def test_init_repository(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            project_id = 10868464
            repository_path = os.path.join(directory, str(project_id))
            expected = os.path.join(
                directory, str(project_id), 'squib'
            )

            # Act
            attributes = Attributes(
                self.rawattributes, database=Database(self.rawsettings),
                goptions=self.rawgoptions
            )
            try:
                attributes.database.connect()
                actual = attributes._init_repository(
                    project_id, repository_path
                )

                # Assert
                self.assertTrue(len(os.listdir(repository_path)) > 0)
                self.assertTrue(expected in actual)
            finally:
                attributes.database.disconnect()
Пример #4
0
    def test_init_repository(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            project_id = 10868464
            repository_path = os.path.join(directory, str(project_id))
            expected = os.path.join(
                directory, str(project_id), 'squib'
            )

            # Act
            attributes = Attributes(
                self.rawattributes, database=Database(self.rawsettings),
                goptions=self.rawgoptions
            )
            try:
                attributes.database.connect()
                actual = attributes._init_repository(
                    project_id, repository_path
                )

                # Assert
                self.assertTrue(len(os.listdir(repository_path)) > 0)
                self.assertTrue(expected in actual)
            finally:
                attributes.database.disconnect()
Пример #5
0
def main():
    """
    Main execution flow.
    """
    try:
        args = process_arguments()

        config = utilities.read(args.config_file)
        manifest = utilities.read(args.manifest_file)

        # TODO: Refactor
        core.config = config
        utilities.TOKENIZER = core.Tokenizer()

        database = Database(config['options']['datasource'])
        globaloptions = {
            'today': config['options']['today'],
            'timeout': config['options']['timeout']
        }
        attributes = Attributes(manifest['attributes'], database, args.cleanup,
                                args.key_string, **globaloptions)

        if not os.path.exists(args.repositories_root):
            os.makedirs(args.repositories_root, exist_ok=True)

        table = 'reaper_results'
        if args.goldenset:
            table = 'reaper_goldenset'

        _run = run.Run(args.repositories_root, attributes, database,
                       config['options']['threshold'], args.num_processes)
        _run.run([int(line) for line in args.repositories_sample], table)
    except Exception as e:
        extype, exvalue, extrace = sys.exc_info()
        traceback.print_exception(extype, exvalue, extrace)
Пример #6
0
    def test_cleanup(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            project_id = 10868464
            repository_home = os.path.join(directory, str(project_id))
            attributes = Attributes(
                self.rawattributes, database=Database(self.rawsettings),
                goptions=self.rawgoptions
            )
            try:
                attributes.database.connect()
                attributes._init_repository(project_id, repository_home)

                # Act
                attributes._cleanup(repository_home)

                # Assert
                self.assertFalse(os.path.exists(repository_home))
            finally:
                attributes.database.disconnect()
    def test_requires_source(self):
        # Arrange
        keystring = 'mchs'

        # Act
        attributes = Attributes(
            self.rawattributes, database=None, keystring=keystring,
            goptions=self.rawgoptions
        )

        # Assert
        self.assertFalse(attributes.requires_source)

        # Arrange
        keystring = 'dualmichs'

        # Act
        attributes = Attributes(
            self.rawattributes, database=None, keystring=keystring
        )

        # Assert
        self.assertTrue(attributes.requires_source)
    def test_is_persitence_enabled(self):
        # Arrange
        keystring = 'dualmichs'

        # Act
        attributes = Attributes(
            self.rawattributes, database=None, keystring=keystring,
            goptions=self.rawgoptions
        )

        # Assert
        self.assertFalse(attributes.is_persistence_enabled)

        # Arrange
        keystring = 'dualMichs'

        # Act
        attributes = Attributes(
            self.rawattributes, database=None, keystring=keystring
        )

        # Assert
        self.assertTrue(attributes.is_persistence_enabled)
    def test_keystring(self):
        # Arrange
        keystring = 'DuAlIcH'

        # Act
        attributes = Attributes(
            self.rawattributes, database=None, keystring=keystring,
            goptions=self.rawgoptions
        )

        # Assert
        for attribute in attributes.attributes:
            index = str.find(keystring.lower(), attribute.initial)
            if index == -1:
                self.assertFalse(attribute.enabled)
            else:
                self.assertTrue(attribute.enabled)
                if keystring[index].isupper():
                    self.assertTrue(attribute.persist)
                else:
                    self.assertFalse(attribute.persist)
    def test_init(self):
        # Arrange
        expected = len(self.rawattributes)

        # Act
        attributes = Attributes(
            self.rawattributes, database=None, goptions=self.rawgoptions
        )

        # Assert
        self.assertEqual(expected, len(attributes.attributes))
        for attribute in attributes.attributes:
            self.assertNotEqual('', attribute.name)
            self.assertNotEqual('', attribute.initial)
            self.assertIsInstance(attribute.weight, numbers.Number)
            self.assertIsInstance(attribute.enabled, bool)
            self.assertIsInstance(attribute.essential, bool)
            self.assertIsInstance(attribute.persist, bool)
            self.assertIsInstance(attribute.dependencies, list)
            self.assertIsInstance(attribute.options, dict)
            self.assertIsInstance(attribute.reference, types.ModuleType)
Пример #11
0
    def setUp(self):
        parentpath = (
            os.path.abspath(
                os.path.join(
                    os.path.dirname(os.path.realpath(__file__)),
                    os.pardir
                )
            )
        )
        manifestpath = os.path.join(parentpath, 'manifest.json')

        configpath = os.path.join(parentpath, 'config.json')
        rawsettings = None
        with open(configpath, 'r') as file_:
            rawsettings = json.load(file_)
        self.database = Database(rawsettings['options']['datasource'])

        rawmanifest = None
        with open(manifestpath, 'r') as file_:
            rawmanifest = json.load(file_)
        self.attributes = Attributes(rawmanifest['attributes'], self.database)

        self.threshold = rawsettings['options']['threshold']
        self.processes = 2
    def test_cleanup(self):
        with tempfile.TemporaryDirectory() as directory:
            # Arrange
            project_id = 10868464
            repository_home = os.path.join(directory, str(project_id))
            attributes = Attributes(
                self.rawattributes, database=Database(self.rawsettings),
                goptions=self.rawgoptions
            )
            try:
                attributes.database.connect()
                attributes._init_repository(project_id, repository_home)

                # Act
                attributes._cleanup(repository_home)

                # Assert
                self.assertFalse(os.path.exists(repository_home))
            finally:
                attributes.database.disconnect()
    def test_score(self):
        # Global Arrange
        attributes = Attributes(
            self.rawattributes, database=None, goptions=self.rawgoptions
        )

        # Arrange
        rresults = {
            'architecture': 9.00,
            'community': 9.00,
            'continuous_integration': True,
            'documentation': 9.00,
            'history': 9.00,
            'license': True,
            'management': 9.00,
            'state': 'active',
            'unit_test': 9.00,
        }
        expected = 100.00

        # Act
        actual = attributes.score(rresults)

        # Assert
        self.assertEqual(expected, actual)

        # Arrange
        rresults = {
            'architecture': 9.00,
            'community': 9.00,
            'continuous_integration': True,
            'documentation': 0,
            'history': 9.00,
            'license': True,
            'management': 9.00,
            'state': 'active',
            'unit_test': 9.00,
        }
        expected = 80.00

        # Act
        actual = attributes.score(rresults)

        # Assert
        self.assertEqual(expected, actual)

        # Arrange
        rresults = {
            'architecture': 9.00,
            'community': 9.00,
            'continuous_integration': True,
            'documentation': 9.00,
            'history': 9.00,
            'license': False,
            'management': 9.00,
            'state': 'active',
            'unit_test': 9.00,
        }
        expected = 0

        # Act
        actual = attributes.score(rresults)

        # Assert
        self.assertEqual(expected, actual)