コード例 #1
0
 def setUp(self):
     plugins = ['gnatmetric', 'gnatcheck', 'sonar-config']
     self.gnathub = GNAThub(Project.simple(), plugins=plugins)
コード例 #2
0
ファイル: test.py プロジェクト: AdaCore/gnatdashboard
    def testDatabaseContent(self):
        PROJECT = Project.simple()

        # Create path to /obj and /codepeer folders
        OBJ_FOLDER = 'obj'
        OBJ_PATH = os.path.join(Project.simple().install_dir, OBJ_FOLDER)

        CODEPEER_FOLDER = 'codepeer'
        CODEPEER_PATH = os.path.join(OBJ_PATH, CODEPEER_FOLDER)

        # Run GNAThub with Codepeer
        gnathub = GNAThub(PROJECT, plugins=['codepeer'])

        # Check that /obj and /codepeer folders exists
        assert os.path.exists(OBJ_PATH), 'Object folder should exist'
        assert os.path.exists(CODEPEER_PATH), 'Codepeer folder should exist'

        # Check the existence of expected simple.csv file
        CSV_COUNT = 0
        CSV_PATH = CODEPEER_PATH
        for entry in os.listdir(CODEPEER_PATH):
            if entry.endswith('.csv') and entry.startswith('simple'):
                CSV_COUNT += 1
                CSV_PATH = os.path.join(CSV_PATH, entry)
        assert CSV_COUNT == 1, 'simple.csv should be generated in /obj/codepeer folder'
        assert os.path.isfile(CSV_PATH), 'simple.csv is a file'

        # Check .csv content
        columns = defaultdict(list) # each value in each column is appended to a list
        with open(CSV_PATH) as f:
            # read rows into a dictionary format
            reader = csv.DictReader(f)
            # read a row as {column1: value1, column2: value2,...}
            for row in reader:
                # go over each column name and value
                for (k,v) in row.items():
                    # append the value into the appropriate list based on column name k
                    columns[k].append(v)

        # Check column 'Line'
        self.assertListEqual(columns['Line'], EXPECTED_LINES_FROM_CSV)
        # Check column 'Column'
        self.assertListEqual(columns['Column'], EXPECTED_COLUMNS_FROM_CSV)
        # Check column 'Category'
        self.assertListEqual(columns['Category'], EXPECTED_CATEGORIES_FROM_CSV)
        # Check column 'Ranking'
        self.assertListEqual(columns['Ranking'], EXPECTED_RANKINGS_FROM_CSV)
        # Check column 'Kind'
        self.assertListEqual(columns['Kind'], EXPECTED_KINDS_FROM_CSV)
        # Check column 'Message'
        self.assertListEqual(columns['Message'], EXPECTED_MESSAGES_FROM_CSV)

        # Checks the analysis report results are as expected
        script_output_file = os.path.abspath('script.out')
        gnathub.run(script=Script.db2cfg(), output=script_output_file)

        parser = SafeConfigParser()
        parser.optionxform = str

        parser.read(script_output_file)
        self.assertListEqual(sorted(parser.sections()), RESULTS)
コード例 #3
0
ファイル: test.py プロジェクト: orhanugurlu/gnatdashboard
    def testDatabaseContent(self):
        PROJECT = Project.simple()

        # Create path to /obj and /codepeer folders
        OBJ_FOLDER = 'obj'
        OBJ_PATH = os.path.join(Project.simple().install_dir, OBJ_FOLDER)

        CODEPEER_FOLDER = 'codepeer'
        CODEPEER_PATH = os.path.join(OBJ_PATH, CODEPEER_FOLDER)

        # Run GNAThub with Codepeer
        gnathub = GNAThub(PROJECT, plugins=['codepeer'])

        # Check that /obj and /codepeer folders exists
        assert os.path.exists(OBJ_PATH), 'Object folder should exist'
        assert os.path.exists(CODEPEER_PATH), 'Codepeer folder should exist'

        # Check the existence of expected simple.csv file
        CSV_COUNT = 0
        CSV_PATH = CODEPEER_PATH
        for entry in os.listdir(CODEPEER_PATH):
            if entry.endswith('.csv') and entry.startswith('simple'):
                CSV_COUNT += 1
                CSV_PATH = os.path.join(CSV_PATH, entry)
        assert CSV_COUNT == 1, 'simple.csv should be generated in /obj/codepeer folder'
        assert os.path.isfile(CSV_PATH), 'simple.csv is a file'

        # Check .csv content
        columns = defaultdict(
            list)  # each value in each column is appended to a list
        with open(CSV_PATH) as f:
            # read rows into a dictionary format
            reader = csv.DictReader(f)
            # read a row as {column1: value1, column2: value2,...}
            for row in reader:
                # go over each column name and value
                for (k, v) in row.items():
                    # append the value into the appropriate list based on column name k
                    columns[k].append(v)

        # Check column 'Line'
        self.assertListEqual(columns['Line'], EXPECTED_LINES_FROM_CSV)
        # Check column 'Column'
        self.assertListEqual(columns['Column'], EXPECTED_COLUMNS_FROM_CSV)
        # Check column 'Category'
        self.assertListEqual(columns['Category'], EXPECTED_CATEGORIES_FROM_CSV)
        # Check column 'Ranking'
        self.assertListEqual(columns['Ranking'], EXPECTED_RANKINGS_FROM_CSV)
        # Check column 'Kind'
        self.assertListEqual(columns['Kind'], EXPECTED_KINDS_FROM_CSV)
        # Check column 'Message'
        self.assertListEqual(columns['Message'], EXPECTED_MESSAGES_FROM_CSV)

        # Checks the analysis report results are as expected
        script_output_file = os.path.abspath('script.out')
        gnathub.run(script=Script.db2cfg(), output=script_output_file)

        parser = SafeConfigParser()
        parser.optionxform = str

        parser.read(script_output_file)
        self.assertListEqual(sorted(parser.sections()), RESULTS)
コード例 #4
0
    def setUp(self):
        self.longMessage = True

        # Run GNAThub with only the sonar-config plugin
        self.gnathub = GNAThub(Project.simple(), plugins=['gnatmetric'])
コード例 #5
0
ファイル: test.py プロジェクト: AdaCore/gnatdashboard
 def setUp(self):
     self.longMessage = True
     self.project = Project.simple()
     self.project.build()
     self.gnathub = GNAThub(self.project, plugins=['gnatstack'])
コード例 #6
0
 def setUp(self):
     self.longMessage = True
     self.gnathub = GNAThub(Project.simple(), plugins=['gnatmetric'])
コード例 #7
0
ファイル: test.py プロジェクト: AdaCore/gnatdashboard
 def setUp(self):
     self.longMessage = True
     self.project = Project.simple()
     self.project.build()
     self.project.run()
     self.gnathub = GNAThub(self.project, plugins=['gnatstack'])
コード例 #8
0
ファイル: test.py プロジェクト: AdaCore/gnatdashboard
    def testIncrementalSwitch(self):
        PROJECT = Project.simple()

        # Define 'obj' folder name and path
        OBJ_FOLDER = 'obj'
        OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER)

        # 1st step: Run GNAThub without '--incremental' switch
        assert not os.path.exists(OBJ_PATH), 'Object folder should not exist'
        gnathub = GNAThub(PROJECT, plugins=['codepeer'])

        assert os.path.exists(OBJ_PATH), 'Object folder should exist'

        # Check that results are generated in /obj
        METRIX_FILES_COUNT = 0
        METRIX_FILES_FOUND = False

        GNATHUB_DIR_FOUND = False
        GNATHUB_DIR_LEN = 0

        CODEPEER_DIR_FOUND = False
        CODEPEER_DIR_LEN = 0

        for entry in os.listdir(OBJ_PATH):
            if entry.endswith('.metrix') or entry.startswith('metrix'):
                METRIX_FILES_COUNT += 1
            elif os.path.isdir(os.path.join(OBJ_PATH, entry)):
                crt_path = os.path.join(OBJ_PATH, entry)
                if entry == 'gnathub':
                    GNATHUB_DIR_FOUND = True
                    GNATHUB_DIR_LEN = len(os.listdir(crt_path))
                elif entry == 'codepeer':
                    CODEPEER_DIR_FOUND = True
                    CODEPEER_DIR_LEN = len(os.listdir(crt_path))

        METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0
        assert not METRIX_FILE_FOUND, 'No metrix should be generated in /obj folder'
        assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder'
        assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder'

        # Check DB content
        gnathub.run(script='check-db-codepeer.py')

        # 2nd step: Run GNAThub without '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['gnatmetric'])

        GNATHUB_DIR_FOUND = False
        GNATHUB_DIR_LEN = 0

        CODEPEER_DIR_FOUND = False
        CODEPEER_DIR_LEN = 0

        for entry in os.listdir(OBJ_PATH):
            if entry.endswith('.metrix') or entry.startswith('metrix'):
                METRIX_FILES_COUNT += 1
            elif os.path.isdir(os.path.join(OBJ_PATH, entry)):
                crt_path = os.path.join(OBJ_PATH, entry)
                if entry == 'gnathub':
                    GNATHUB_DIR_FOUND = True
                    GNATHUB_DIR_LEN = len(os.listdir(crt_path))
                elif entry == 'codepeer':
                    CODEPEER_DIR_FOUND = True
                    CODEPEER_DIR_LEN = len(os.listdir(crt_path))

        METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0
        assert METRIX_FILE_FOUND, 'Metrix should be generated in /obj folder'
        assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder'
        assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder'

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-metrics.py')

        # 3rd step: Run GNAThub with '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['codepeer'], incremental=True)

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-incremental.py')

        # 4th step: Run GNAThub with '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['codepeer'], incremental=True)

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-incremental.py')

        # 5th step: Run GNAThub with '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['gnatmetric'], incremental=True)

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-incremental.py')
コード例 #9
0
 def setUp(self):
     self.longMessage = True
     self.gnathub = GNAThub(
         Project.simple(), plugins=['codepeer'],
         mocks=[CodePeerExecutable])
コード例 #10
0
ファイル: test.py プロジェクト: vser1/gnatdashboard
    def testIncrementalSwitch(self):
        PROJECT = Project.simple()

        # Define 'obj' folder name and path
        OBJ_FOLDER = 'obj'
        OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER)

        # 1st step: Run GNAThub without '--incremental' switch
        assert not os.path.exists(OBJ_PATH), 'Object folder should not exist'
        gnathub = GNAThub(PROJECT, plugins=['codepeer'])

        assert os.path.exists(OBJ_PATH), 'Object folder should exist'

        # Check that results are generated in /obj
        METRIX_FILES_COUNT = 0
        METRIX_FILES_FOUND = False

        GNATHUB_DIR_FOUND = False
        GNATHUB_DIR_LEN = 0

        CODEPEER_DIR_FOUND = False
        CODEPEER_DIR_LEN = 0

        for entry in os.listdir(OBJ_PATH):
            if entry.endswith('.metrix') or entry.startswith('metrix'):
                METRIX_FILES_COUNT += 1
            elif os.path.isdir(os.path.join(OBJ_PATH, entry)):
                crt_path = os.path.join(OBJ_PATH, entry)
                if entry == 'gnathub':
                    GNATHUB_DIR_FOUND = True
                    GNATHUB_DIR_LEN = len(os.listdir(crt_path))
                elif entry == 'codepeer':
                    CODEPEER_DIR_FOUND = True
                    CODEPEER_DIR_LEN = len(os.listdir(crt_path))

        METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0
        assert not METRIX_FILE_FOUND, 'No metrix should be generated in /obj folder'
        assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder'
        assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder'

        # Check DB content
        gnathub.run(script='check-db-codepeer.py')

        # 2nd step: Run GNAThub without '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['gnatmetric'])

        GNATHUB_DIR_FOUND = False
        GNATHUB_DIR_LEN = 0

        CODEPEER_DIR_FOUND = False
        CODEPEER_DIR_LEN = 0

        for entry in os.listdir(OBJ_PATH):
            if entry.endswith('.metrix') or entry.startswith('metrix'):
                METRIX_FILES_COUNT += 1
            elif os.path.isdir(os.path.join(OBJ_PATH, entry)):
                crt_path = os.path.join(OBJ_PATH, entry)
                if entry == 'gnathub':
                    GNATHUB_DIR_FOUND = True
                    GNATHUB_DIR_LEN = len(os.listdir(crt_path))
                elif entry == 'codepeer':
                    CODEPEER_DIR_FOUND = True
                    CODEPEER_DIR_LEN = len(os.listdir(crt_path))

        METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0
        assert METRIX_FILE_FOUND, 'Metrix should be generated in /obj folder'
        assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder'
        assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder'

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-metrics.py')

        # 3rd step: Run GNAThub with '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['codepeer'], incremental=True)

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-incremental.py')

        # 4th step: Run GNAThub with '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['codepeer'], incremental=True)

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-incremental.py')

        # 5th step: Run GNAThub with '--incremental' switch
        gnathub = GNAThub(PROJECT, plugins=['gnatmetric'], incremental=True)

        # Check DB content after gnatmetric run
        gnathub.run(script='check-db-incremental.py')
コード例 #11
0
ファイル: test.py プロジェクト: AdaCore/gnatdashboard
 def setUp(self):
     self.longMessage = True
     os.environ['USE_LIBADALANG_TOOLS'] = '1'
     self.gnathub = GNAThub(Project.simple(), plugins=['gnatmetric'])
コード例 #12
0
ファイル: test.py プロジェクト: orhanugurlu/gnatdashboard
 def setUp(self):
     self.longMessage = True
     os.environ['USE_LIBADALANG_TOOLS'] = '1'
     self.gnathub = GNAThub(Project.simple(), plugins=['gnatmetric'])
コード例 #13
0
ファイル: test.py プロジェクト: vser1/gnatdashboard
    def testSubdirsSwitch(self):
        PROJECT = Project.simple()
        PLUGINS = ['gnatmetric', 'gnatcheck', 'codepeer']

        # Define 'obj' folder name and path
        OBJ_FOLDER = 'obj'
        OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER)

        # Define 'test_metrix' as target folder name and path of --subdirs switch
        SUBDIRS_FOLDER = 'test_metrix'
        NEW_OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER,
                                    SUBDIRS_FOLDER)

        # 1st step of test : Run GNAThub without '--subdirs' switch only for gnatmetric plugin
        assert not os.path.exists(OBJ_PATH), 'Object folder should not exist'
        gnathub = GNAThub(PROJECT, plugins=PLUGINS)

        assert os.path.exists(OBJ_PATH), 'Object folder should exist'
        assert not os.path.exists(
            NEW_OBJ_PATH), 'New object folder should not have been created yet'

        # Check that metrix and gnatcheck results are generated in /obj
        METRIX_FILES_COUNT = 0
        METRIX_FILES_FOUND = False

        GNATCHECK_FILES_COUNT = 0
        GNATCHECK_FILES_FOUND = False

        GNATHUB_DIR_FOUND = False
        GNATHUB_DIR_LEN = 0

        CODEPEER_DIR_FOUND = False
        CODEPEER_DIR_LEN = 0

        for entry in os.listdir(OBJ_PATH):
            if entry.endswith('.metrix') or entry.startswith('metrix'):
                METRIX_FILES_COUNT += 1
            elif entry.startswith('gnatcheck') and entry.endswith('.out'):
                GNATCHECK_FILES_COUNT += 1
            elif os.path.isdir(os.path.join(OBJ_PATH, entry)):
                crt_path = os.path.join(OBJ_PATH, entry)
                if entry == 'gnathub':
                    GNATHUB_DIR_FOUND = True
                    GNATHUB_DIR_LEN = len(os.listdir(crt_path))
                elif entry == 'codepeer':
                    CODEPEER_DIR_FOUND = True
                    CODEPEER_DIR_LEN = len(os.listdir(crt_path))

        METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0
        GNATCHECK_FILES_FOUND = GNATCHECK_FILES_COUNT == 2  # expected value is 2

        assert METRIX_FILE_FOUND, 'Metrix should be generated in /obj folder'
        assert GNATCHECK_FILES_FOUND, 'Gnatcheck out files should be generated in /obj folder'
        assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder'

        # Run GNAThub with option '--subdirs=test_metrix' only for gnatmetric plugin
        gnathub = GNAThub(PROJECT, plugins=PLUGINS, subdirs=SUBDIRS_FOLDER)
        assert os.path.exists(
            NEW_OBJ_PATH), 'New object folder should have been created'

        # Check that metrix and gnatcheck results are present in '/obj/test_metrix' folder
        NEW_METRIX_FILES_COUNT = 0
        NEW_GNATCHECK_FILES_COUNT = 0

        NEW_GNATHUB_DIR_FOUND = False
        NEW_GNATHUB_DIR_LEN = 0

        NEW_CODEPEER_DIR_FOUND = False
        NEW_CODEPEER_DIR_LEN = 0

        for entry in os.listdir(NEW_OBJ_PATH):
            filename, ext = os.path.splitext(entry)
            if entry.endswith('.metrix') or entry.startswith('metrix'):
                NEW_METRIX_FILES_COUNT += 1
            elif entry.startswith('gnatcheck') and entry.endswith('.out'):
                NEW_GNATCHECK_FILES_COUNT += 1
            elif os.path.isdir(os.path.join(NEW_OBJ_PATH, entry)):
                crt_path = os.path.join(OBJ_PATH, entry)
                if entry == 'gnathub':
                    NEW_GNATHUB_DIR_FOUND = True
                    NEW_GNATHUB_DIR_LEN = len(os.listdir(crt_path))
                elif entry == 'codepeer':
                    NEW_CODEPEER_DIR_FOUND = True
                    NEW_CODEPEER_DIR_LEN = len(os.listdir(crt_path))

        self.assertEqual(
            METRIX_FILES_COUNT, NEW_METRIX_FILES_COUNT,
            'All metrix results should be generated in /obj/test_metrix folder'
        )
        self.assertEqual(
            GNATCHECK_FILES_COUNT, NEW_GNATCHECK_FILES_COUNT,
            'All expected gnatchek results should be generated in /obj/test_metrix folder'
        )

        assert NEW_GNATHUB_DIR_FOUND, 'Codepeer directory should be in /obj/test_metrix folder'
        self.assertEqual(NEW_GNATHUB_DIR_LEN, GNATHUB_DIR_LEN,
                         'GNAThub directories should have same length')

        assert NEW_CODEPEER_DIR_FOUND, 'Codepeer directory should be in /obj/test_metrix folder'
        self.assertEqual(NEW_CODEPEER_DIR_LEN, CODEPEER_DIR_LEN,
                         'Codepeer directories should have same length')