From c6a97939f1254f44318d1496c21a828bb5ed1d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Fri, 13 Dec 2019 23:51:18 +0100 Subject: [PATCH] rename parse_srclib to parese_txt_srclib + test case --- fdroidserver/metadata.py | 6 +++--- tests/metadata.TestCase | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index 26bdcf22..fbf11a44 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -704,7 +704,7 @@ def description_html(s, linkres): return ps.text_html -def parse_srclib(metadatapath): +def parse_txt_srclib(metadatapath): thisinfo = {} @@ -746,7 +746,7 @@ def read_srclibs(): The information read will be accessible as metadata.srclibs, which is a dictionary, keyed on srclib name, with the values each being a dictionary - in the same format as that returned by the parse_srclib function. + in the same format as that returned by the parse_txt_srclib function. A MetaDataException is raised if there are any problems with the srclib metadata. @@ -765,7 +765,7 @@ def read_srclibs(): for metadatapath in sorted(glob.glob(os.path.join(srcdir, '*.txt'))): srclibname = os.path.basename(metadatapath[:-4]) - srclibs[srclibname] = parse_srclib(metadatapath) + srclibs[srclibname] = parse_txt_srclib(metadatapath) def read_metadata(xref=True, check_vcs=[], refresh=True, sort_by_time=False): diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index 686301db..08d4137c 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -23,6 +23,8 @@ print('localmodule: ' + localmodule) if localmodule not in sys.path: sys.path.insert(0, localmodule) +from testcommon import TmpCwd + import fdroidserver.common import fdroidserver.metadata from fdroidserver.exception import MetaDataException @@ -568,6 +570,29 @@ class MetadataTest(unittest.TestCase): UpdateCheckMode: None """)) + def test_parse_txt_srclib(self): + with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir): + with open('JSoup.txt', 'w', encoding='utf-8') as f: + f.write(textwrap.dedent('''\ + # Source details (the only mandatory fields) + Repo Type:git + Repo:https://github.com/jhy/jsoup.git + + # Comma-separated list of subdirs to use. The first existing subdirectory + # found between those given will be used. If none is found or provided, the + # root of the repo directory will be used instead. + Subdir: + + # Any extra commands to prepare the source library + Prepare: + ''')) + srclib = fdroidserver.metadata.parse_txt_srclib('JSoup.txt') + self.assertDictEqual({'Repo': 'https://github.com/jhy/jsoup.git', + 'Repo Type': 'git', + 'Subdir': [''], + 'Prepare': ''}, + srclib) + if __name__ == "__main__": os.chdir(os.path.dirname(__file__))