Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:")
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)
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)
def read_pbxs(pbx_files):
projects = [pbxproj.read(pbx_file) for pbx_file in pbx_files]
return projects