Exemplo n.º 1
0
Arquivo: BOA.py Projeto: zqcui/MUBench
    def query_projects_with_type_usages(self, types_names: List[str], subtypes_names: List[str]) -> List[GitHubProject]:
        projects = []
        query_id = "{}_{}".format("-".join(types_names), "-".join(subtypes_names))
        result_file_name = os.path.join(self.results_path, query_id + ".boaresult")
        if not os.path.exists(result_file_name):
            output = self.__try_query_projects_with_type_usages(subtypes_names)
            output_lines = output.splitlines()
            try:
                results_start_line = output_lines.index("Start output:") + 1
                results_end_line = output_lines.index("===")
                results = str.join(os.linesep, output_lines[results_start_line:results_end_line])
            except ValueError:
                # BOA returned no output
                results = ""

            os.makedirs(os.path.dirname(result_file_name), exist_ok=True)
            io.safe_write(results, result_file_name, append=False)

        with open(result_file_name, 'r') as result_file:
            for line in result_file.readlines():
                if line:
                    project_id = line[8:].strip()
                    if project_id:
                        projects.append(GitHubProject(project_id))

        return projects
Exemplo n.º 2
0
    def query_projects_with_type_usages(
            self, type_name: str, subtype_name: str) -> List[GitHubProject]:
        projects = []
        query_id = "{}_{}".format(type_name, subtype_name)
        result_file_name = os.path.join(os.path.dirname(__file__), "results",
                                        query_id + ".boaresult")
        if not os.path.exists(result_file_name):
            output = self.__try_query_projects_with_type_usages(subtype_name)
            output_lines = output.splitlines()
            try:
                results_start_line = output_lines.index("Start output:") + 1
                results_end_line = output_lines.index("===")
                results = str.join(
                    os.linesep,
                    output_lines[results_start_line:results_end_line])
            except ValueError:
                # BOA returned no output
                results = ""

            io.safe_write(results, result_file_name, append=False)

        with open(result_file_name, 'r') as result_file:
            for line in result_file.readlines():
                if line:
                    projects.append(GitHubProject(line[8:].strip()))

        return projects
Exemplo n.º 3
0
def __create_image(dot_graph, working_directory, image_name):
    image_path = join(working_directory, image_name)
    if not exists(image_path):
        makedirs(working_directory, exist_ok=True)
        dot_path = image_path + ".dot"
        safe_write(dot_graph, dot_path, append=False)
        Shell.exec("dot -v -Tsvg -o'{}' '{}'".format(image_path, dot_path))
        remove(dot_path)
Exemplo n.º 4
0
    def test_md5_no_whitespace(self):
        temp_dir = mkdtemp(prefix="mubench-detector_")
        md5_path = join(temp_dir, "test.md5")
        safe_write("-test-md5-", md5_path, append=False)

        detector = Detector("-path-", "id", [])
        detector.md5_path = md5_path

        assert_equals("-test-md5-", detector.md5)
Exemplo n.º 5
0
def __create_image(dot_graph, working_directory, image_name):
    image_path = join(working_directory, image_name)
    if not exists(image_path):
        makedirs(working_directory, exist_ok=True)
        dot_path = image_path + ".dot"
        #can be used to restrict iterations during graph layouting
        #dot_graph = dot_graph.replace("\n", "\nnslimit=100;\n",1)
        safe_write(dot_graph, dot_path, append=False)
        Shell.exec("dot -v -Tsvg -o'{}' '{}'".format(image_path, dot_path))
        remove(dot_path)
Exemplo n.º 6
0
    def test_zip_dir_contents_suffix_is_not_a_conflict(self):
        src1 = join(self.temp_dir, "src1")
        src2 = join(self.temp_dir, "src2")
        safe_write("b", join(src1, "-subdir-", "-conflict-"), False)
        safe_write("a", join(src2, "-conflict-"), False)
        sources = [src1, src2]
        destination = join(self.temp_dir, "archive")

        zip_dir_contents(sources, destination)

        extract_destination = join(self.temp_dir, "extracted")
        with zipfile.ZipFile(destination, 'r') as zip_file:
            zip_file.extractall(extract_destination)

        assert exists(join(extract_destination, "-conflict-")) and \
            exists(join(extract_destination, "-subdir-", "-conflict-"))
Exemplo n.º 7
0
    def test_zip_dir_contents_skips_file_on_conflict(self):
        src1 = join(self.temp_dir, "src1")
        src2 = join(self.temp_dir, "src2")
        safe_write("a", join(src1, "-conflict-"), False)
        safe_write("b", join(src2, "-conflict-"), False)
        sources = [src1, src2]
        destination = join(self.temp_dir, "archive")

        zip_dir_contents(sources, destination)

        extract_destination = join(self.temp_dir, "extracted")
        with zipfile.ZipFile(destination, 'r') as zip_file:
            zip_file.extractall(extract_destination)

        assert_equals("a\n", safe_read(join(extract_destination,
                                            "-conflict-")))
Exemplo n.º 8
0
    def test_valid_by_md5_file(self):
        create_file(self.file)
        md5_file = join(self.tmp, "my.md5")
        safe_write(EMPTY_FILE_MD5, md5_file, append=False)

        validate_file(self.file, md5_file)
Exemplo n.º 9
0
 def test_writes_file_safely(self):
     some_content = "Some content"
     safe_write(some_content, self.test_file, append=False)
     with open(self.test_file) as actual_file:
         assert actual_file.read() == some_content + '\n'