Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testPrintSeparateSections(self):
dobj = objects().parse(PBXObjectTest.MINIMUM_OBJ)
string = dobj.__repr__()
self.assertTrue(string.__contains__("/* Begin phase1 section */"))
self.assertTrue(string.__contains__("/* End phase1 section */"))
self.assertTrue(string.__contains__("/* Begin phase2 section */"))
self.assertTrue(string.__contains__("/* End phase2 section */"))
def testGetComment(self):
key = PBXKey("123", None)
key._get_comment = lambda: "comment"
self.assertEqual(key.__repr__(), "123 /* comment */")
def __repr__(self):
return u'// !$*UTF8*$!\n' + super(XcodeProject, self).__repr__()
def testParseCreateAttributes(self):
obj = {"a": "varA", "b": [1, 2, 3], "c": {"c1": "varC1"}}
dobj = PBXGenericObject().parse(obj)
self.assertEqual(dobj.a, "varA")
self.assertEqual(dobj.b, [1, 2, 3])
self.assertIsNotNone(dobj.c)
def testGetItem(self):
obj = {"a": "varA", "b": [1, 2, 3], "c": {"c1": "FDDF6A571C68E5B100D7A645"}}
dobj = PBXGenericObject().parse(obj)
self.assertIsInstance(dobj["c"]["c1"], PBXKey)
self.assertIsNone(dobj['X'])
def testResolveComment(self):
obj = {"a": {"name": "A"}, "b": {"path": "B"}, "c": {"c1": "FDDF6A571C68E5B100D7A645"}}
dobj = PBXGenericObject().parse(obj)
self.assertEqual(dobj._resolve_comment('a'), 'A')
self.assertEqual(dobj._resolve_comment('b'), 'B')
self.assertEqual(dobj._resolve_comment('c'), None)
def testPrintObject(self):
obj = {"a": "varA", "b": [1, 2, 3], "c": {"c1": "FDDF6A571C68E5B100D7A645"}}
dobj = PBXGenericObject().parse(obj)
expected = '{\n\ta = varA;\n\tb = (\n\t\t1,\n\t\t2,\n\t\t3,\n\t);\n\tc = {\n\t\tc1 = FDDF6A571C68E5B100D7A645;\n\t};\n}'
self.assertEqual(dobj.__repr__(), expected)
def testParseCreateObjectOfRightTypes(self):
obj = {"objects": {"id": {"isa": "type"}}}
dobj = PBXGenericObject().parse(obj)
self.assertIsInstance(dobj.objects, objects)
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)
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)