Skip to content

Commit

Permalink
convert assertions from nosetest to pytest style
Browse files Browse the repository at this point in the history
  • Loading branch information
kronenthaler committed Oct 11, 2023
1 parent e0c4200 commit a6c23ff
Show file tree
Hide file tree
Showing 31 changed files with 669 additions and 656 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ coverage.xml
# Mac OS X cruft
.DS_Store
tests/parent_group
*.bak
62 changes: 31 additions & 31 deletions tests/TestPBXGenericObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,98 +9,98 @@ class PBXGenericObjectTest(unittest.TestCase):
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)
assert dobj.a == "varA"
assert dobj.b == [1, 2, 3]
assert dobj.c is not None

def testParseCreateObjectOfRightTypes(self):
obj = {"objects": {"id": {"isa": "type"}}}
dobj = PBXGenericObject().parse(obj)

self.assertIsInstance(dobj.objects, objects)
assert isinstance(dobj.objects, objects)

def testParseKey(self):
obj = "FDDF6A571C68E5B100D7A645"
dobj = PBXGenericObject().parse(obj)

self.assertIsInstance(dobj, PBXKey)
assert isinstance(dobj, PBXKey)

def testEscapeItem(self):
self.assertEqual(PBXGenericObject._escape("/bin/sh"), "/bin/sh")
self.assertEqual(PBXGenericObject._escape("abcdefghijklmnopqrstuvwyz0123456789"),
"abcdefghijklmnopqrstuvwyz0123456789")
self.assertEqual(PBXGenericObject._escape("some spaces"), '"some spaces"')
self.assertEqual(PBXGenericObject._escape("a.valid_id."), "a.valid_id.")
self.assertEqual(PBXGenericObject._escape("a-invalid-id"), '"a-invalid-id"')
self.assertEqual(PBXGenericObject._escape("<group>"), '"<group>"')
self.assertEqual(PBXGenericObject._escape("script \\ continuation"), '"script \\\\ continuation"')
self.assertEqual(PBXGenericObject._escape("/bin/sh find .. -name '*.framework'", exclude=["\'"]),
"\"/bin/sh find .. -name '*.framework'\"")
assert PBXGenericObject._escape("/bin/sh") == "/bin/sh"
assert PBXGenericObject._escape("abcdefghijklmnopqrstuvwyz0123456789") == \
"abcdefghijklmnopqrstuvwyz0123456789"
assert PBXGenericObject._escape("some spaces") == '"some spaces"'
assert PBXGenericObject._escape("a.valid_id.") == "a.valid_id."
assert PBXGenericObject._escape("a-invalid-id") == '"a-invalid-id"'
assert PBXGenericObject._escape("<group>") == '"<group>"'
assert PBXGenericObject._escape("script \\ continuation") == '"script \\\\ continuation"'
assert PBXGenericObject._escape("/bin/sh find .. -name '*.framework'", exclude=["\'"]) == \
"\"/bin/sh find .. -name '*.framework'\""

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)
assert dobj.__repr__() == expected

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'])
assert isinstance(dobj["c"]["c1"], PBXKey)
assert dobj['X'] is None

def testSetItemNone(self):
obj = {}
dobj = PBXGenericObject().parse(obj)

self.assertIsNone(dobj['something'])
assert dobj['something'] is None

dobj['something'] = None
self.assertIsNone(dobj['something'])
assert dobj['something'] is None

def testSetItemString(self):
obj = {}
dobj = PBXGenericObject().parse(obj)

self.assertIsNone(dobj['something'])
assert dobj['something'] is None

dobj['something'] = 'yes'
self.assertEqual(dobj['something'], 'yes')
assert dobj['something'] == 'yes'

def testSetItemListOfZero(self):
obj = {}
dobj = PBXGenericObject().parse(obj)

self.assertIsNone(dobj['something'])
assert dobj['something'] is None

dobj['something'] = []
self.assertIsNone(dobj['something'])
assert dobj['something'] is None

def testSetItemListOfOne(self):
obj = {}
dobj = PBXGenericObject().parse(obj)

self.assertIsNone(dobj['something'])
assert dobj['something'] is None

dobj['something'] = ['yes']
self.assertEqual(dobj['something'], 'yes')
assert dobj['something'] == 'yes'

def testSetItemListOfTwo(self):
obj = {}
dobj = PBXGenericObject().parse(obj)

self.assertIsNone(dobj['something'])
assert dobj['something'] is None

dobj['something'] = ['yes', 'yes']
self.assertEqual(dobj['something'], ['yes', 'yes'])
assert dobj['something'] == ['yes', 'yes']

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)
assert dobj._resolve_comment('a') == 'A'
assert dobj._resolve_comment('b') == 'B'
assert dobj._resolve_comment('c') == None
2 changes: 1 addition & 1 deletion tests/TestPBXKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def testGetComment(self):
key = PBXKey("123", None)
key._get_comment = lambda: "comment"

self.assertEqual(key.__repr__(), "123 /* comment */")
assert key.__repr__() == "123 /* comment */"
56 changes: 28 additions & 28 deletions tests/TestPBXObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@ def testParseNonObject(self):
obj = [1, 2, 3]
dobj = objects().parse(obj)

self.assertIsInstance(dobj, list)
assert isinstance(dobj, list)

def testGetKeys(self):
dobj = objects().parse(PBXObjectTest.MINIMUM_OBJ)
keys = dobj.get_keys()

self.assertListEqual(keys, ['1', '2', '3'])
assert keys == ['1', '2', '3']

def testParseGroupsPhases(self):
dobj = objects().parse(PBXObjectTest.MINIMUM_OBJ)

self.assertEqual(dobj._sections.__len__(), 2)
self.assertEqual(dobj._sections['phase1'].__len__(), 2)
self.assertEqual(dobj._sections['phase2'].__len__(), 1)
assert dobj._sections.__len__() == 2
assert dobj._sections['phase1'].__len__() == 2
assert dobj._sections['phase2'].__len__() == 1

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 */'))
assert string.__contains__('/* Begin phase1 section */')
assert string.__contains__('/* End phase1 section */')
assert string.__contains__('/* Begin phase2 section */')
assert string.__contains__('/* End phase2 section */')

def testGetItem(self):
dobj = objects().parse(PBXObjectTest.MINIMUM_OBJ)
self.assertIsNotNone(dobj['1'])
self.assertIsNone(dobj['4'])
assert dobj['1'] is not None
assert dobj['4'] is None

def testContains(self):
dobj = objects().parse(PBXObjectTest.MINIMUM_OBJ)
self.assertTrue('1' in dobj)
self.assertFalse('4' in dobj)
assert '1' in dobj
assert not ('4' in dobj)

def testGetObjectsInsection(self):
dobj = objects().parse(PBXObjectTest.MINIMUM_OBJ)
sections = dobj.get_objects_in_section('phase1', 'phase2')

self.assertSetEqual(set(sections).intersection(dobj._sections['phase1']), set(dobj._sections['phase1']))
self.assertSetEqual(set(sections).intersection(dobj._sections['phase2']), set(dobj._sections['phase2']))
self.assertEqual(dobj.get_objects_in_section('phaseX'), [])
assert set(sections).intersection(dobj._sections['phase1']) == set(dobj._sections['phase1'])
assert set(sections).intersection(dobj._sections['phase2']) == set(dobj._sections['phase2'])
assert dobj.get_objects_in_section('phaseX') == []

def testGetTargets(self):
obj = {
Expand All @@ -60,11 +60,11 @@ def testGetTargets(self):
}
dobj = objects().parse(obj)

self.assertEqual(dobj.get_targets().__len__(), 3)
self.assertEqual(dobj.get_targets('app').__len__(), 1)
self.assertEqual(dobj.get_targets('report').__len__(), 1)
self.assertEqual(dobj.get_targets('whatever').__len__(), 0)
self.assertEqual(dobj.get_targets(['app', 'something']).__len__(), 2)
assert dobj.get_targets().__len__() == 3
assert dobj.get_targets('app').__len__() == 1
assert dobj.get_targets('report').__len__() == 1
assert dobj.get_targets('whatever').__len__() == 0
assert dobj.get_targets(['app', 'something']).__len__() == 2

def testGetConfigurationTargets(self):
obj = {
Expand All @@ -80,16 +80,16 @@ def testGetConfigurationTargets(self):
dobj = objects().parse(obj)

result = [x for x in dobj.get_configurations_on_targets()]
self.assertEqual(result.__len__(), 4)
self.assertSetEqual({x.id for x in result}, {'5', '6', '7', '8'})
assert result.__len__() == 4
assert {x.id for x in result} == {'5', '6', '7', '8'}

result = [x for x in dobj.get_configurations_on_targets(target_name='app')]
self.assertEqual(result.__len__(), 2)
self.assertSetEqual({x.id for x in result}, {'5', '6'})
assert result.__len__() == 2
assert {x.id for x in result} == {'5', '6'}

result = [x for x in dobj.get_configurations_on_targets(configuration_name='Release')]
self.assertSetEqual({x.id for x in result}, {'5', '7'})
assert {x.id for x in result} == {'5', '7'}

result = [x for x in dobj.get_configurations_on_targets(target_name='app', configuration_name='Release')]
self.assertEqual(result.__len__(), 1)
self.assertSetEqual({x.id for x in result}, {'5'})
assert result.__len__() == 1
assert {x.id for x in result} == {'5'}
23 changes: 12 additions & 11 deletions tests/TestXCodeProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest

from pbxproj import XcodeProject
import re


class XCodeProjectTest(unittest.TestCase):
Expand Down Expand Up @@ -47,68 +48,68 @@ def tearDown(self):
def testSaveOnGivenPath(self):
XcodeProject().save("results/sample")

self.assertTrue(os.path.exists("results/sample"))
assert os.path.exists("results/sample")

def testSaveOnDefaultPath(self):
XcodeProject({}, "results/default").save()

self.assertTrue(os.path.exists("results/default"))
assert os.path.exists("results/default")

def testBackup(self):
project = XcodeProject({}, 'results/default')
project.save('results/default')
backup_name = project.backup()

self.assertRegex(backup_name, r'_[0-9]{6}-[0-9]{6}\.backup')
assert re.search(r'_[0-9]{6}-[0-9]{6}\.backup', backup_name)

def testGetIds(self):
project = XcodeProject({'objects':{'1':{'isa':'a'}, '2':{'isa':'a'}}})

self.assertListEqual(project.get_ids(), ['1', '2'])
assert project.get_ids() == ['1', '2']

def testGetBuildFilesForFile(self):
project = XcodeProject(self.obj)

build_files = project.get_build_files_for_file('file1')
self.assertListEqual(build_files, [project.objects['build_file1']])
assert build_files == [project.objects['build_file1']]

def testGetTargetByNameExisting(self):
project = XcodeProject(self.obj)

target = project.get_target_by_name('app')
self.assertEqual(target, project.objects['1'])
assert target == project.objects['1']

def testGetTargetByNameNonExisting(self):
project = XcodeProject(self.obj)

target = project.get_target_by_name('non-existing')
self.assertIsNone(target)
assert target is None

def testGetBuildPhasesByName(self):
project = XcodeProject(self.obj)

build_phases = project.get_build_phases_by_name('PBXGenericBuildPhase')
self.assertEqual(build_phases.__len__(), 2)
assert build_phases.__len__() == 2

def testGetBuildConfigurationsByTarget(self):
project = XcodeProject(self.obj)

build_configurations = project.get_build_configurations_by_target(
'app')
self.assertListEqual(build_configurations, ['Release', 'Debug'])
assert build_configurations == ['Release', 'Debug']

def testGetBuildConfigurationsByTargetNotExistent(self):
project = XcodeProject(self.obj)

build_configurations = project.get_build_configurations_by_target(
'appThatDoesNotExists')
self.assertIsNone(build_configurations)
assert build_configurations is None

def testConsistency(self):
with open('samplescli/massive.pbxproj', 'r') as file:
original = file.read()
project = XcodeProject.load('samplescli/massive.pbxproj')
saved = project.__repr__() + '\n'

self.assertEqual(saved, original)
assert saved == original

Loading

0 comments on commit a6c23ff

Please sign in to comment.