예제 #1
0
    def test_should_add_all_misuse_ids(self):
        uut = DataEntityLists(["p.v1.m1", "p.v2.m1", "p.v2.m2", "p"], [])

        actual = uut.get_misuse_white_list("p.v2")

        expected = ["p.v2.m1", "p.v2.m2"]
        assert_equals(expected, actual)
예제 #2
0
    def test_should_add_all_project_ids(self):
        uut = DataEntityLists(["p1.v.m", "p2.v", "p3"], [])

        actual = uut.get_project_white_list()

        expected = ["p1", "p2", "p3"]
        assert_equals(expected, actual)
예제 #3
0
    def test_should_add_all_version_ids(self):
        uut = DataEntityLists(["p.v1.m", "p.v2", "p"], [])

        actual = uut.get_version_white_list("p")

        expected = ["p.v1", "p.v2"]
        assert_equals(expected, actual)
예제 #4
0
    def __is_filtered(project_id: str,
                      data_entity_lists: DataEntityLists) -> bool:
        white_list = data_entity_lists.get_project_white_list()
        black_list = data_entity_lists.black_list

        is_whitelisted = not white_list or project_id in white_list
        is_blacklisted = project_id in black_list
        return is_blacklisted or not is_whitelisted
예제 #5
0
    def __is_filtered(version_id: str, misuse_id: str,
                      data_entity_lists: DataEntityLists) -> bool:
        white_list = data_entity_lists.get_misuse_white_list(version_id)
        black_list = data_entity_lists.black_list

        is_whitelisted = not white_list or misuse_id in white_list
        is_blacklisted = misuse_id in black_list
        return is_blacklisted or not is_whitelisted
예제 #6
0
    def test_filters_blacklisted(self):
        project = create_project("-id-", base_path=self.temp_dir)
        create_file(project._project_file)
        uut = CollectProjectsTask(self.temp_dir)

        actual = uut.run(DataEntityLists([], ["-id-"]))

        assert_equals([], actual)
예제 #7
0
    def __is_filtered(project_id: str, version: ProjectVersion,
                      data_entity_lists: DataEntityLists) -> bool:
        version_id = version.id
        white_list = data_entity_lists.get_version_white_list(project_id)
        black_list = data_entity_lists.black_list

        is_whitelisted = not white_list or version_id in white_list
        is_blacklisted = version_id in black_list

        return is_blacklisted or not is_whitelisted
예제 #8
0
    def test_finds_all_projects(self):
        p1 = create_project("p1", base_path=self.temp_dir)
        create_file(p1._project_file)
        p2 = create_project("p2", base_path=self.temp_dir)
        create_file(p2._project_file)
        uut = CollectProjectsTask(self.temp_dir)

        actual = uut.run(DataEntityLists([], []))

        assert_equals([p1, p2], actual)
예제 #9
0
    def test_filters_non_whitelisted(self):
        project = create_project("-project-")
        version = create_version("-version-", misuses=[], project=project)
        create_misuse("-id-", version=version)
        uut = CollectMisusesTask()

        actual = uut.run(
            version, DataEntityLists(["-project-.-version-.-other-id-"], []))

        assert_equals([], actual)
예제 #10
0
    def test_whitelisted_version(self):
        misuse = create_misuse("-id-")
        project = create_project("-project-")
        version = create_version("-version-",
                                 misuses=[misuse],
                                 project=project)
        uut = CollectMisusesTask()

        actual = uut.run(version, DataEntityLists(["-project-.-version-"], []))

        assert_equals([misuse], actual)
예제 #11
0
    def test_finds_all_misuses(self):
        m1 = create_misuse("-m1-")
        m2 = create_misuse("-m2-")
        project = create_project("-project-")
        version = create_version("-version-",
                                 misuses=[m1, m2],
                                 project=project)
        uut = CollectMisusesTask()

        actual = uut.run(version, DataEntityLists([], []))

        assert_equals([m1, m2], actual)
예제 #12
0
파일: benchmark.py 프로젝트: zqcui/MUBench
    def __init__(self, config):
        self.config = config

        white_list = []
        black_list = []
        if 'white_list' in config:
            white_list.extend(config.white_list)
        if 'black_list' in config:
            black_list.extend(config.black_list)

        if 'datasets' in config:
            for dataset in config.datasets:
                white_list.extend(
                    get_white_list(config.datasets_file_path, dataset))

        self.data_entity_lists = DataEntityLists(white_list, black_list)
예제 #13
0
_INDEX_PATH = os.path.join(__MUBENCH_ROOT_PATH, "checkouts-xp", "index.csv")


class PrintIndexTask:
    def run(self, project: Project, version: ProjectVersion, misuse: Misuse):
        print("{}\t{}\t{}\t{}\t{}\t{}\t{}".format(
            project.id, version.version_id, misuse.misuse_id,
            ':'.join(version.source_dirs), misuse.location.file,
            misuse.location.method, "\t".join(misuse.apis)),
              file=open(_INDEX_PATH, "a"))


datasets = sys.argv[1:]

white_list = []
for dataset in datasets:
    white_list.extend(get_white_list(__MUBENCH_DATASETS_FILE, dataset.lower()))
initial_parameters = [DataEntityLists(white_list, [])]

runner = TaskRunner([
    CollectProjectsTask(__MUBENCH_DATA_PATH),
    CollectVersionsTask(False),
    CollectMisusesTask(),
    PrintIndexTask()
])

if os.path.exists(_INDEX_PATH):
    os.remove(_INDEX_PATH)

runner.run(*initial_parameters)