mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
always open Android source files as UTF-8
Android Studio recommends "you use UTF-8 encoding whenever possible", so this code assumes the files use UTF-8. UTF-8 is also the default encoding on GNU/Linux and macOS. https://sites.google.com/a/android.com/tools/knownissues/encoding Windows will probably default to UTF16, since that's the native encoding for files. So forcing things to use UTF-8 should help compatibility.
This commit is contained in:
parent
0c31c4a5ab
commit
48c4354629
5 changed files with 26 additions and 20 deletions
|
|
@ -315,14 +315,15 @@ class CommonTest(unittest.TestCase):
|
|||
fdroidserver.common.prepare_source(FakeVcs(), app, build,
|
||||
fdroidclient_testdir, fdroidclient_testdir, fdroidclient_testdir)
|
||||
|
||||
with open(os.path.join(fdroidclient_testdir, 'build.gradle'), 'r') as f:
|
||||
filedata = f.read()
|
||||
fdroidclient_testdir = Path(fdroidclient_testdir)
|
||||
build_gradle = fdroidclient_testdir / 'build.gradle'
|
||||
filedata = build_gradle.read_text(encoding='utf-8')
|
||||
self.assertIsNotNone(
|
||||
re.search(r"\s+compileSdkVersion %s\s+" % testint, filedata)
|
||||
)
|
||||
|
||||
with open(os.path.join(fdroidclient_testdir, 'AndroidManifest.xml')) as f:
|
||||
filedata = f.read()
|
||||
androidmanifest_xml = fdroidclient_testdir / 'AndroidManifest.xml'
|
||||
filedata = androidmanifest_xml.read_text(encoding='utf-8')
|
||||
self.assertIsNone(re.search('android:debuggable', filedata))
|
||||
self.assertIsNotNone(
|
||||
re.search('android:versionName="%s"' % build.versionName, filedata)
|
||||
|
|
@ -342,10 +343,10 @@ class CommonTest(unittest.TestCase):
|
|||
)
|
||||
|
||||
subdir = 'baz/bar'
|
||||
subdir_path = os.path.join(app_build_dir, subdir)
|
||||
os.makedirs(subdir_path)
|
||||
with open(os.path.join(subdir_path, 'build.gradle'), 'w') as fp:
|
||||
fp.write('// just a test placeholder')
|
||||
subdir_path = Path(app_build_dir) / subdir
|
||||
subdir_path.mkdir(parents=True, exist_ok=True)
|
||||
build_gradle = subdir_path / 'build.gradle'
|
||||
build_gradle.write_text('// just a test placeholder', encoding='utf-8')
|
||||
|
||||
config = dict()
|
||||
fdroidserver.common.fill_config_defaults(config)
|
||||
|
|
@ -921,7 +922,7 @@ class CommonTest(unittest.TestCase):
|
|||
self.assertNotEqual(0, len(files))
|
||||
for f in files:
|
||||
appid, versionCode = os.path.splitext(os.path.basename(f))[0][12:].split('_')
|
||||
with open(f) as fp:
|
||||
with open(f, encoding='utf-8') as fp:
|
||||
m = fdroidserver.common.APK_ID_TRIPLET_REGEX.match(fp.read())
|
||||
if m:
|
||||
self.assertEqual(appid, m.group(1))
|
||||
|
|
@ -962,6 +963,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_get_sdkversions_androguard(self):
|
||||
"""This is a sanity test that androguard isn't broken"""
|
||||
|
||||
def get_minSdkVersion(apkfile):
|
||||
apk = fdroidserver.common._get_androguard_APK(apkfile)
|
||||
return fdroidserver.common.get_min_sdk_version(apk)
|
||||
|
|
@ -1852,9 +1854,9 @@ class CommonTest(unittest.TestCase):
|
|||
self.assertEqual([],
|
||||
data['fdroiddata']['untrackedFiles'])
|
||||
dirtyfile = 'dirtyfile'
|
||||
with open(dirtyfile, 'w') as fp:
|
||||
with open(dirtyfile, 'w', encoding='utf-8') as fp:
|
||||
fp.write('this is just a test')
|
||||
with open(file_in_git, 'a') as fp:
|
||||
with open(file_in_git, 'a', encoding='utf-8') as fp:
|
||||
fp.write('\nappend some stuff')
|
||||
self.assertEqual([],
|
||||
data['fdroiddata']['modifiedFiles'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue