1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-15 03:20:10 +01:00

scanner.TestCase: format

This commit is contained in:
linsui 2024-09-14 22:23:52 +08:00
parent 0d148d58e1
commit 528760acc8

View File

@ -1,9 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import collections
import glob import glob
import inspect import inspect
import logging import logging
import os import os
import pathlib
import re import re
import shutil import shutil
import sys import sys
@ -11,13 +13,12 @@ import tempfile
import textwrap import textwrap
import unittest import unittest
import uuid import uuid
import yaml
import zipfile import zipfile
import collections
import pathlib
from unittest import mock
from dataclasses import asdict from dataclasses import asdict
from datetime import datetime, timedelta from datetime import datetime, timedelta
from unittest import mock
import yaml
localmodule = os.path.realpath( localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..') os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
@ -26,11 +27,12 @@ print('localmodule: ' + localmodule)
if localmodule not in sys.path: if localmodule not in sys.path:
sys.path.insert(0, localmodule) sys.path.insert(0, localmodule)
from testcommon import TmpCwd, mkdtemp, mock_open_to_str, parse_args_for_test
import fdroidserver.build import fdroidserver.build
import fdroidserver.common import fdroidserver.common
import fdroidserver.metadata import fdroidserver.metadata
import fdroidserver.scanner import fdroidserver.scanner
from testcommon import TmpCwd, mkdtemp, mock_open_to_str, parse_args_for_test
# Always use built-in default rules so changes in downloaded rules don't break tests. # Always use built-in default rules so changes in downloaded rules don't break tests.
@ -783,12 +785,13 @@ class Test_main(unittest.TestCase):
(doesn't test how they get processed) (doesn't test how they get processed)
""" """
self.args = ["com.example.app"] self.args = ["com.example.app"]
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir), mock.patch( with (
"sys.exit", self.exit_func tempfile.TemporaryDirectory() as tmpdir,
), mock.patch("sys.argv", ["fdroid scanner", *self.args]), mock.patch( TmpCwd(tmpdir),
"fdroidserver.common.read_app_args", self.read_app_args_func mock.patch("sys.exit", self.exit_func),
), mock.patch( mock.patch("sys.argv", ["fdroid scanner", *self.args]),
"fdroidserver.scanner.scan_binary", self.scan_binary_func mock.patch("fdroidserver.common.read_app_args", self.read_app_args_func),
mock.patch("fdroidserver.scanner.scan_binary", self.scan_binary_func),
): ):
fdroidserver.scanner.main() fdroidserver.scanner.main()
@ -804,12 +807,13 @@ class Test_main(unittest.TestCase):
(doesn't test how they get processed) (doesn't test how they get processed)
""" """
self.args = ["local.application.apk"] self.args = ["local.application.apk"]
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir), mock.patch( with (
"sys.exit", self.exit_func tempfile.TemporaryDirectory() as tmpdir,
), mock.patch("sys.argv", ["fdroid scanner", *self.args]), mock.patch( TmpCwd(tmpdir),
"fdroidserver.common.read_app_args", self.read_app_args_func mock.patch("sys.exit", self.exit_func),
), mock.patch( mock.patch("sys.argv", ["fdroid scanner", *self.args]),
"fdroidserver.scanner.scan_binary", self.scan_binary_func mock.patch("fdroidserver.common.read_app_args", self.read_app_args_func),
mock.patch("fdroidserver.scanner.scan_binary", self.scan_binary_func),
): ):
pathlib.Path(self.args[0]).touch() pathlib.Path(self.args[0]).touch()
fdroidserver.scanner.main() fdroidserver.scanner.main()