mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-08-17 11:50:11 +02:00
Windows seems to require this, otherwise this happens: Traceback (most recent call last): File "tests/update.TestCase", line 737, in test_translate_per_build_anti_features apps = fdroidserver.metadata.read_metadata(xref=True) File "C:\Users\travis\build\fdroidtravis\fdroidserver\fdroidserver\metadata.py", line 813, in read_metadata app = parse_metadata(metadatapath, appid in check_vcs, refresh) File "C:\Users\travis\build\fdroidtravis\fdroidserver\fdroidserver\metadata.py", line 1023, in parse_metadata parse_yaml_metadata(mf, app) File "C:\Users\travis\build\fdroidtravis\fdroidserver\fdroidserver\metadata.py", line 1073, in parse_yaml_metadata yamldata = yaml.safe_load(mf) File "C:\python37\lib\site-packages\yaml\__init__.py", line 162, in safe_load return load(stream, SafeLoader) File "C:\python37\lib\site-packages\yaml\__init__.py", line 112, in load loader = Loader(stream) File "C:\python37\lib\site-packages\yaml\loader.py", line 34, in __init__ Reader.__init__(self, stream) File "C:\python37\lib\site-packages\yaml\reader.py", line 85, in __init__ self.determine_encoding() File "C:\python37\lib\site-packages\yaml\reader.py", line 124, in determine_encoding self.update_raw() File "C:\python37\lib\site-packages\yaml\reader.py", line 178, in update_raw data = self.stream.read(size) File "C:\python37\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 37: character maps to <undefined>
111 lines
3.1 KiB
Python
Executable File
111 lines
3.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import logging
|
|
import optparse
|
|
import os
|
|
import sys
|
|
import unittest
|
|
import tempfile
|
|
import textwrap
|
|
from unittest import mock
|
|
from pathlib import Path
|
|
|
|
|
|
from testcommon import TmpCwd
|
|
|
|
localmodule = Path(__file__).resolve().parent.parent
|
|
print('localmodule: ' + str(localmodule))
|
|
if localmodule not in sys.path:
|
|
sys.path.insert(0, str(localmodule))
|
|
|
|
from fdroidserver import common
|
|
from fdroidserver import rewritemeta
|
|
from fdroidserver.exception import FDroidException
|
|
|
|
|
|
class RewriteMetaTest(unittest.TestCase):
|
|
'''fdroidserver/publish.py'''
|
|
|
|
def setUp(self):
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
self.basedir = localmodule / 'tests'
|
|
self.tmpdir = localmodule / '.testfiles'
|
|
self.tmpdir.mkdir(exist_ok=True)
|
|
# TODO: Python3.6: Accepts a path-like object.
|
|
os.chdir(str(self.basedir))
|
|
|
|
def test_rewrite_scenario_trivial(self):
|
|
|
|
sys.argv = ['rewritemeta', 'a', 'b']
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
|
|
Path('metadata').mkdir()
|
|
with Path('metadata/a.yml').open('w') as f:
|
|
f.write('AutoName: a')
|
|
with Path('metadata/b.yml').open('w') as f:
|
|
f.write('AutoName: b')
|
|
|
|
rewritemeta.main()
|
|
|
|
self.assertEqual(
|
|
Path('metadata/a.yml').read_text(encoding='utf-8'),
|
|
textwrap.dedent(
|
|
'''\
|
|
License: Unknown
|
|
|
|
AutoName: a
|
|
|
|
AutoUpdateMode: None
|
|
UpdateCheckMode: None
|
|
'''
|
|
),
|
|
)
|
|
|
|
self.assertEqual(
|
|
Path('metadata/b.yml').read_text(encoding='utf-8'),
|
|
textwrap.dedent(
|
|
'''\
|
|
License: Unknown
|
|
|
|
AutoName: b
|
|
|
|
AutoUpdateMode: None
|
|
UpdateCheckMode: None
|
|
'''
|
|
),
|
|
)
|
|
|
|
def test_rewrite_scenario_yml_no_ruamel(self):
|
|
sys.argv = ['rewritemeta', 'a']
|
|
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
|
|
Path('metadata').mkdir()
|
|
with Path('metadata/a.yml').open('w') as f:
|
|
f.write('AutoName: a')
|
|
|
|
def boom(*args):
|
|
raise FDroidException(' '.join((str(x) for x in args)))
|
|
|
|
with mock.patch('importlib.util.find_spec', boom):
|
|
with self.assertRaises(FDroidException):
|
|
rewritemeta.main()
|
|
|
|
self.assertEqual(
|
|
Path('metadata/a.yml').read_text(encoding='utf-8'), 'AutoName: a'
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = optparse.OptionParser()
|
|
parser.add_option(
|
|
"-v",
|
|
"--verbose",
|
|
action="store_true",
|
|
default=False,
|
|
help="Spew out even more information than normal",
|
|
)
|
|
(common.options, args) = parser.parse_args(['--verbose'])
|
|
|
|
newSuite = unittest.TestSuite()
|
|
newSuite.addTest(unittest.makeSuite(RewriteMetaTest))
|
|
unittest.main(failfast=False)
|