Esempio n. 1
0
    def test_fixtures(self):
        parsing_fixtures_path = fixture_path("parse")

        project_files = [file for file in listpath(parsing_fixtures_path) if file.endswith(".pbxproj")]

        self.logger.debug("parsing %d files..." % len(project_files))

        for project_file in project_files:
            self.logger.debug("trying to parse file %s" % project_file)

            data = pbxproj.read(project_file)
            f_o = wrap_with_codec(StringIO(), data.get_encoding())
            pbxproj.write(f_o, data)

            #now compare the content of the written file with the original file
            #this should stay the same
            original_content = open(project_file).read()
            new_content = f_o.getvalue()
            f_o.close()

            #if assert will fail, generate a diff for this failure
            if not new_content == original_content:
                self.logger.error("failed to generate an exact replica, diff follows:")
                diff_lines = difflib.unified_diff(original_content.splitlines(), new_content.splitlines())
                for line in diff_lines:
                    self.logger.error(line)

            self.assertEquals(new_content, original_content, "%s was not correctly parsed" % project_file)
Esempio n. 2
0
    def test_merge_fixtures(self):
        merge_fixtures_path = fixture_path("merge")
        merge_projects = listpath(merge_fixtures_path)
        merge_tasks = [listpath(merge_project) for merge_project in merge_projects]

        for merge_task in chain.from_iterable(merge_tasks):
            task_files = listpath(merge_task)
            project_files = load_merge_task(task_files)

            self.logger.info("merging base %s with my %s and their %s and comparing with %s..." % project_files)

            projects = [pbxproj.read(project_file) for project_file in project_files]
            base, mine, theirs, merged = projects

            merged_buffer = StringIO()
            merged_buffer = wrap_with_codec(merged_buffer, codec=base.get_encoding())
            merged_project = merge_pbxs(base, mine, theirs)
            pbxproj.write(merged_buffer, merged_project)

            #now compare the content of the written file with the original file
            #this should stay the same
            expected_merged_content = open(project_files[-1]).read()
            merged_content = merged_buffer.getvalue()
            merged_buffer.close()

            #if assert will fail, generate a diff for this failure
            if not merged_content == expected_merged_content:
                self.logger.error("failed to generate an exact replica, diff follows:")
                diff_lines = difflib.unified_diff(expected_merged_content.splitlines(), merged_content.splitlines())
                for line in diff_lines:
                    self.logger.error(line)

            self.assertEquals(merged_content, expected_merged_content, "%s was not correctly merged" % merge_task)
Esempio n. 3
0
def run_benchmark(pbxproj, test_files, runs=10, timer_impl=ProfileTimer):
    timer = timer_impl()

    results = [-1.0] * runs
    for i in range(runs):
        gc.collect()
        with timer:
            for test_file in test_files:
                basef, minef, theirsf = test_file

                base, mine, theirs = (pbxproj.read(f) for f in (basef, minef, theirsf))
                pbxproj.merge.merge_pbxs(base, mine, theirs)

        results[i] = timer.duration_in_seconds()

    return BenchmarkResult(results)
Esempio n. 4
0
def run_benchmark(pbxproj, test_files, runs=10, timer_impl=ProfileTimer):
    timer = timer_impl()

    results = [-1.0]*runs
    for i in range(runs):
        gc.collect()
        with timer:
            for test_file in test_files:
                basef, minef, theirsf = test_file

                base, mine, theirs = (pbxproj.read(f) for f in (basef, minef, theirsf))
                pbxproj.merge.merge_pbxs(base, mine, theirs)

        results[i] = timer.duration_in_seconds()

    return BenchmarkResult(results)
Esempio n. 5
0
def read_pbxs(pbx_files):
    projects = [pbxproj.read(pbx_file) for pbx_file in pbx_files]

    return projects
Esempio n. 6
0
def merge_pbx_files(basef, minef, theirsf):
    base, mine, theirs = (pbxproj.read(f) for f in (basef, minef, theirsf))

    merged_project = merge_pbxs(base, mine, theirs)
Esempio n. 7
0
def read_pbxs(pbx_files):
    projects = [pbxproj.read(pbx_file) for pbx_file in pbx_files]

    return projects
def merge_pbx_files(basef, minef, theirsf):
    base, mine, theirs = (pbxproj.read(f) for f in (basef, minef, theirsf))

    merged_project = merge_pbxs(base, mine, theirs)