mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
🏟️ add test for _parse_from_pbxproj
Also fix lint issues
This commit is contained in:
parent
450765490b
commit
f742799a9d
3 changed files with 26 additions and 4 deletions
|
|
@ -629,7 +629,7 @@ def parse_ipa(ipa_path, file_size, sha256):
|
||||||
if info.filename.endswith("/embedded.mobileprovision"):
|
if info.filename.endswith("/embedded.mobileprovision"):
|
||||||
print("parsing", info.filename)
|
print("parsing", info.filename)
|
||||||
with ipa_zip.open(info) as mopro_file:
|
with ipa_zip.open(info) as mopro_file:
|
||||||
mopro_content_info = cms.ContentInfo.load(mopro_file.read())
|
mopro_content_info = asn1crypto.cms.ContentInfo.load(mopro_file.read())
|
||||||
mopro_payload_info = mopro_content_info['content']
|
mopro_payload_info = mopro_content_info['content']
|
||||||
mopro_payload = mopro_payload_info['encap_content_info']['content'].native
|
mopro_payload = mopro_payload_info['encap_content_info']['content'].native
|
||||||
mopro = biplist.readPlistFromString(mopro_payload)
|
mopro = biplist.readPlistFromString(mopro_payload)
|
||||||
|
|
@ -1670,6 +1670,10 @@ def _get_ipa_icon(src_dir):
|
||||||
def _parse_from_pbxproj(pbxproj_path, key):
|
def _parse_from_pbxproj(pbxproj_path, key):
|
||||||
"""Parse values from apple project files.
|
"""Parse values from apple project files.
|
||||||
|
|
||||||
|
This is a naive regex based parser. Should this proofe to unreliable we
|
||||||
|
might want to consider using a dedicated pbxproj parser:
|
||||||
|
https://pypi.org/project/pbxproj/
|
||||||
|
|
||||||
e.g. when looking for key 'ASSETCATALOG_COMPILER_APPICON_NAME'
|
e.g. when looking for key 'ASSETCATALOG_COMPILER_APPICON_NAME'
|
||||||
This function will extract 'MyIcon' from if the provided file
|
This function will extract 'MyIcon' from if the provided file
|
||||||
contains this line:
|
contains this line:
|
||||||
|
|
|
||||||
|
|
@ -2223,11 +2223,29 @@ class TestGetIpaIcon(unittest.TestCase):
|
||||||
""")
|
""")
|
||||||
|
|
||||||
pfp = mock.Mock(return_value="fake_icon")
|
pfp = mock.Mock(return_value="fake_icon")
|
||||||
with(mock.patch("fdroidserver.update._parse_from_pbxproj", pfp)):
|
with mock.patch("fdroidserver.update._parse_from_pbxproj", pfp):
|
||||||
p = fdroidserver.update._get_ipa_icon(tmpdir)
|
p = fdroidserver.update._get_ipa_icon(tmpdir)
|
||||||
self.assertEqual(str(icondir / "yep"), p)
|
self.assertEqual(str(icondir / "yep"), p)
|
||||||
|
|
||||||
|
|
||||||
|
class TestParseFromPbxproj(unittest.TestCase):
|
||||||
|
def test_parse_from_pbxproj(self):
|
||||||
|
self.maxDiff = None
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
with open(Path(tmpdir) / "asdf.pbxproj", 'w', encoding="utf-8") as f:
|
||||||
|
f.write("""
|
||||||
|
230jfaod=flc'
|
||||||
|
ASSETCATALOG_COMPILER_APPICON_NAME = MyIcon;
|
||||||
|
cm opa1c p[m
|
||||||
|
""")
|
||||||
|
v = fdroidserver.update._parse_from_pbxproj(
|
||||||
|
Path(tmpdir) / "asdf.pbxproj",
|
||||||
|
"ASSETCATALOG_COMPILER_APPICON_NAME"
|
||||||
|
)
|
||||||
|
self.assertEqual(v, "MyIcon")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue