diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f60b3e46..f1ac2337a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: exclude: ^docs/conf.py$ - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black args: [--target-version, py38, --preview] diff --git a/src/bandersnatch/tests/plugins/test_allowlist_name.py b/src/bandersnatch/tests/plugins/test_allowlist_name.py index e1f60ad61..7a870cc53 100644 --- a/src/bandersnatch/tests/plugins/test_allowlist_name.py +++ b/src/bandersnatch/tests/plugins/test_allowlist_name.py @@ -30,7 +30,8 @@ def tearDown(self) -> None: self.tempdir.cleanup() def test__plugin__loads__explicitly_enabled(self) -> None: - mock_config(contents="""\ + mock_config( + contents="""\ [mirror] storage-backend = filesystem workers = 2 @@ -38,7 +39,8 @@ def test__plugin__loads__explicitly_enabled(self) -> None: [plugins] enabled = allowlist_project -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_project_plugins() names = [plugin.name for plugin in plugins] @@ -46,20 +48,23 @@ def test__plugin__loads__explicitly_enabled(self) -> None: self.assertEqual(len(plugins), 1) def test__plugin__loads__default(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 [plugins] -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_project_plugins() names = [plugin.name for plugin in plugins] self.assertNotIn("allowlist_project", names) def test__filter__matches__package(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -71,7 +76,8 @@ def test__filter__matches__package(self) -> None: [allowlist] packages = foo -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = {"foo": ""} @@ -80,7 +86,8 @@ def test__filter__matches__package(self) -> None: self.assertIn("foo", mirror.packages_to_sync.keys()) def test__filter__nomatch_package(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -92,7 +99,8 @@ def test__filter__nomatch_package(self) -> None: [allowlist] packages = foo -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = {"foo": "", "foo2": ""} @@ -102,7 +110,8 @@ def test__filter__nomatch_package(self) -> None: self.assertNotIn("foo2", mirror.packages_to_sync.keys()) def test__filter__name_only(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -114,7 +123,8 @@ def test__filter__name_only(self) -> None: [allowlist] packages = foo==1.2.3 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = {"foo": "", "foo2": ""} @@ -124,7 +134,8 @@ def test__filter__name_only(self) -> None: self.assertNotIn("foo2", mirror.packages_to_sync.keys()) def test__filter__varying__specifiers(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -137,7 +148,8 @@ def test__filter__varying__specifiers(self) -> None: packages = foo==1.2.3 bar~=3.0,<=1.5 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = { "foo": "", @@ -149,7 +161,8 @@ def test__filter__varying__specifiers(self) -> None: self.assertEqual({"foo": "", "bar": ""}, mirror.packages_to_sync) def test__filter__commented__out(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -162,7 +175,8 @@ def test__filter__commented__out(self) -> None: packages = foo==1.2.3 # inline comment # bar -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = { "foo": "", @@ -191,11 +205,13 @@ def tearDown(self) -> None: self.tempdir.cleanup() def test__plugin__loads__explicitly_enabled(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = allowlist_release -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_release_plugins() names = [plugin.name for plugin in plugins] @@ -203,7 +219,8 @@ def test__plugin__loads__explicitly_enabled(self) -> None: self.assertEqual(len(plugins), 1) def test__plugin__doesnt_load__explicitly__disabled(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -211,14 +228,16 @@ def test__plugin__doesnt_load__explicitly__disabled(self) -> None: [plugins] enabled = allowlist_package -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_release_plugins() names = [plugin.name for plugin in plugins] self.assertNotIn("allowlist_release", names) def test__filter__matches__release(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -229,7 +248,8 @@ def test__filter__matches__release(self) -> None: [allowlist] packages = foo==1.2.0 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -243,7 +263,8 @@ def test__filter__matches__release(self) -> None: self.assertEqual(pkg.releases, {"1.2.0": {}}) def test__filter__matches__release__commented__inline(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -254,7 +275,8 @@ def test__filter__matches__release__commented__inline(self) -> None: [allowlist] packages = foo==1.2.0 # some inline comment -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -268,7 +290,8 @@ def test__filter__matches__release__commented__inline(self) -> None: self.assertEqual(pkg.releases, {"1.2.0": {}}) def test__dont__filter__prereleases(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -279,7 +302,8 @@ def test__dont__filter__prereleases(self) -> None: [allowlist] packages = foo<=1.2.0 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -300,7 +324,8 @@ def test__dont__filter__prereleases(self) -> None: self.assertEqual(pkg.releases, {"1.1.0a2": {}, "1.1.1beta1": {}, "1.2.0": {}}) def test__casing__no__affect(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -311,7 +336,8 @@ def test__casing__no__affect(self) -> None: [allowlist] packages = Foo<=1.2.0 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -342,7 +368,8 @@ def tearDown(self) -> None: self.tempdir.cleanup() def test__plugin__loads__explicitly_enabled(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -350,7 +377,8 @@ def test__plugin__loads__explicitly_enabled(self) -> None: [plugins] enabled = project_requirements_pinned -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_release_plugins() names = [plugin.name for plugin in plugins] @@ -358,7 +386,8 @@ def test__plugin__loads__explicitly_enabled(self) -> None: self.assertEqual(len(plugins), 1) def test__plugin__doesnt_load__explicitly__disabled(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem workers = 2 @@ -366,7 +395,8 @@ def test__plugin__doesnt_load__explicitly__disabled(self) -> None: [plugins] enabled = allowlist_package -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_release_plugins() names = [plugin.name for plugin in plugins] @@ -374,13 +404,16 @@ def test__plugin__doesnt_load__explicitly__disabled(self) -> None: def test__filter__matches__release(self) -> None: with open(Path(self.tempdir.name) / "requirements.txt", "w") as fh: - fh.write("""\ + fh.write( + """\ # This is needed for workshop 1 # foo==1.2.0 # via -r requirements.in -""") +""" + ) - mock_config(f"""\ + mock_config( + f"""\ [mirror] storage-backend = filesystem workers = 2 @@ -393,7 +426,8 @@ def test__filter__matches__release(self) -> None: requirements_path = {self.tempdir.name} requirements = requirements.txt -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -408,11 +442,14 @@ def test__filter__matches__release(self) -> None: def test__filter__matches__release_latest(self) -> None: with open(Path(self.tempdir.name) / "requirements.txt", "w") as fh: - fh.write("""\ + fh.write( + """\ foo==1.2.0 # via -r requirements.in -""") +""" + ) - mock_config(f"""\ + mock_config( + f"""\ [mirror] storage-backend = filesystem @@ -427,7 +464,8 @@ def test__filter__matches__release_latest(self) -> None: requirements_path = {self.tempdir.name} requirements = requirements.txt -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -443,13 +481,16 @@ def test__filter__matches__release_latest(self) -> None: def test__filter__find_files(self) -> None: absolute_file_path = Path(self.tempdir.name) / "requirements.txt" with open(absolute_file_path, "w") as fh: - fh.write("""\ + fh.write( + """\ # This is needed for workshop 1 # foo==1.2.0 # via -r requirements.in -""") +""" + ) - mock_config(f"""\ + mock_config( + f"""\ [mirror] storage-backend = filesystem workers = 2 @@ -460,7 +501,8 @@ def test__filter__find_files(self) -> None: [allowlist] requirements = {absolute_file_path} -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) @@ -475,13 +517,16 @@ def test__filter__find_files(self) -> None: def test__filter__requirements__pip__options(self) -> None: absolute_file_path = Path(self.tempdir.name) / "requirements.txt" with open(absolute_file_path, "w") as fh: - fh.write("""\ + fh.write( + """\ --extra-index-url https://self-hosted-foo.netname/simple --trusted-host self-hosted-foo.netname foo==1.2.0 # via -r requirements.in -""") +""" + ) - mock_config(f"""\ + mock_config( + f"""\ [mirror] storage-backend = filesystem workers = 2 @@ -492,7 +537,8 @@ def test__filter__requirements__pip__options(self) -> None: [allowlist] requirements = {absolute_file_path} -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) @@ -506,24 +552,31 @@ def test__filter__requirements__pip__options(self) -> None: def test__filter__find__glob__files(self) -> None: with open(Path(self.tempdir.name) / "requirements-project1.txt", "w") as fh: - fh.write("""\ + fh.write( + """\ # foo==1.2.0 # via -r requirements.in -""") +""" + ) with open(Path(self.tempdir.name) / "requirements-project2.txt", "w") as fh: - fh.write("""\ + fh.write( + """\ # bar==2.3.0 # via -r requirements.in -""") +""" + ) with open(Path(self.tempdir.name) / "project3.txt", "w") as fh: - fh.write("""\ + fh.write( + """\ # baz==4.5.1 # via -r requirements.in -""") +""" + ) - mock_config(f"""\ + mock_config( + f"""\ [mirror] storage-backend = filesystem workers = 2 @@ -536,7 +589,8 @@ def test__filter__find__glob__files(self) -> None: requirements = # Importing all the requirements-*.txt from the chosen folder requirements-*.txt -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) @@ -560,11 +614,14 @@ def test__filter__find__glob__files(self) -> None: def test__filter__requirements__utf16__encoding(self) -> None: absolute_file_path = Path(self.tempdir.name) / "requirements.txt" with open(absolute_file_path, "w", encoding="UTF-16") as fh: - fh.write("""\ + fh.write( + """\ foo==1.2.0 # via -r requirements.in -""") +""" + ) - mock_config(f"""\ + mock_config( + f"""\ [mirror] storage-backend = filesystem workers = 2 @@ -575,7 +632,8 @@ def test__filter__requirements__utf16__encoding(self) -> None: [allowlist] requirements = {absolute_file_path} -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) diff --git a/src/bandersnatch/tests/plugins/test_blocklist_name.py b/src/bandersnatch/tests/plugins/test_blocklist_name.py index 47c97edb7..983d8b257 100644 --- a/src/bandersnatch/tests/plugins/test_blocklist_name.py +++ b/src/bandersnatch/tests/plugins/test_blocklist_name.py @@ -31,11 +31,13 @@ def tearDown(self) -> None: self.tempdir = None def test__plugin__loads__explicitly_enabled(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_project -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_project_plugins() names = [plugin.name for plugin in plugins] @@ -43,34 +45,40 @@ def test__plugin__loads__explicitly_enabled(self) -> None: self.assertEqual(len(plugins), 1) def test__plugin__doesnt_load__explicitly__disabled(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_release -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_project_plugins() names = [plugin.name for plugin in plugins] self.assertNotIn("blocklist_project", names) def test__plugin__loads__default(self) -> None: - mock_config("""\ + mock_config( + """\ [blocklist] -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_project_plugins() names = [plugin.name for plugin in plugins] self.assertNotIn("blocklist_project", names) def test__filter__matches__package(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_project [blocklist] packages = foo -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = {"foo": ""} @@ -79,13 +87,15 @@ def test__filter__matches__package(self) -> None: self.assertNotIn("foo", mirror.packages_to_sync.keys()) def test__filter__nomatch_package(self) -> None: - mock_config("""\ + mock_config( + """\ [blocklist] plugins = blocklist_project packages = foo - """) + """ + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = {"foo2": ""} @@ -94,7 +104,8 @@ def test__filter__nomatch_package(self) -> None: self.assertIn("foo2", mirror.packages_to_sync.keys()) def test__filter__name_only(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem @@ -105,7 +116,8 @@ def test__filter__name_only(self) -> None: [blocklist] packages = foo==1.2.3 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = {"foo": "", "foo2": ""} @@ -115,7 +127,8 @@ def test__filter__name_only(self) -> None: self.assertIn("foo2", mirror.packages_to_sync.keys()) def test__filter__varying__specifiers(self) -> None: - mock_config("""\ + mock_config( + """\ [mirror] storage-backend = filesystem @@ -128,7 +141,8 @@ def test__filter__varying__specifiers(self) -> None: foo==1.2.3 bar~=3.0,<=1.5 snu -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) mirror.packages_to_sync = { "foo": "", @@ -162,11 +176,13 @@ def tearDown(self) -> None: self.tempdir = None def test__plugin__loads__explicitly_enabled(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_release -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_release_plugins() names = [plugin.name for plugin in plugins] @@ -174,25 +190,29 @@ def test__plugin__loads__explicitly_enabled(self) -> None: self.assertEqual(len(plugins), 1) def test__plugin__doesnt_load__explicitly__disabled(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_package -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_release_plugins() names = [plugin.name for plugin in plugins] self.assertNotIn("blocklist_release", names) def test__filter__matches__release(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_release [blocklist] packages = foo==1.2.0 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -206,14 +226,16 @@ def test__filter__matches__release(self) -> None: self.assertEqual(pkg.releases, {"1.2.1": {}}) def test__dont__filter__prereleases(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_release [blocklist] packages = foo<=1.2.0 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) @@ -234,14 +256,16 @@ def test__dont__filter__prereleases(self) -> None: self.assertEqual(pkg.releases, {"1.2.1": {}, "1.2.2alpha3": {}, "1.2.3rc1": {}}) def test__casing__no__affect(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_release [blocklist] packages = Foo<=1.2.0 -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) pkg = Package("foo", 1) diff --git a/src/bandersnatch/tests/plugins/test_metadata_plugins.py b/src/bandersnatch/tests/plugins/test_metadata_plugins.py index ab4906202..be4573f54 100644 --- a/src/bandersnatch/tests/plugins/test_metadata_plugins.py +++ b/src/bandersnatch/tests/plugins/test_metadata_plugins.py @@ -29,14 +29,16 @@ def tearDown(self) -> None: self.tempdir.cleanup() def test__size__plugin__loads__and__initializes(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = size_project_metadata [size_project_metadata] max_package_size = 1G -""") +""" + ) plugins = bandersnatch.filter.LoadedFilters().filter_metadata_plugins() names = [plugin.name for plugin in plugins] @@ -47,14 +49,16 @@ def test__size__plugin__loads__and__initializes(self) -> None: self.assertTrue(plugin.initialized) def test__filter__size__only(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = size_project_metadata [size_project_metadata] max_package_size = 2K -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) @@ -75,7 +79,8 @@ def test__filter__size__only(self) -> None: self.assertFalse(pkg.filter_metadata(mirror.filters.filter_metadata_plugins())) def test__filter__size__or__allowlist(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = size_project_metadata @@ -86,7 +91,8 @@ def test__filter__size__or__allowlist(self) -> None: [allowlist] packages = foo -""") +""" + ) mirror = BandersnatchMirror(Path("."), Master(url="https://foo.bar.com")) diff --git a/src/bandersnatch/tests/plugins/test_storage_plugin_s3.py b/src/bandersnatch/tests/plugins/test_storage_plugin_s3.py index 62be26411..1a02c0389 100644 --- a/src/bandersnatch/tests/plugins/test_storage_plugin_s3.py +++ b/src/bandersnatch/tests/plugins/test_storage_plugin_s3.py @@ -141,7 +141,8 @@ def test_scandir(s3_mock: S3Path) -> None: def test_plugin_init(s3_mock: S3Path) -> None: - config_loader = mock_config(""" + config_loader = mock_config( + """ [mirror] directory = /tmp/pypi json = true @@ -161,7 +162,8 @@ def test_plugin_init(s3_mock: S3Path) -> None: aws_secret_access_key = 123456 endpoint_url = http://localhost:9090 signature_version = s3v4 -""") +""" + ) backend = s3.S3Storage(config=config_loader.config) backend.initialize_plugin() @@ -169,7 +171,8 @@ def test_plugin_init(s3_mock: S3Path) -> None: resource, _ = path._accessor.configuration_map.get_configuration(path) assert resource.meta.client.meta.endpoint_url == "http://localhost:9090" - config_loader = mock_config(""" + config_loader = mock_config( + """ [mirror] directory = /tmp/pypi json = true @@ -185,7 +188,8 @@ def test_plugin_init(s3_mock: S3Path) -> None: compare-method = hash [s3] endpoint_url = http://localhost:9090 -""") +""" + ) backend = s3.S3Storage(config=config_loader.config) backend.initialize_plugin() diff --git a/src/bandersnatch/tests/plugins/test_storage_plugins.py b/src/bandersnatch/tests/plugins/test_storage_plugins.py index 555bc8e30..91b2e3777 100644 --- a/src/bandersnatch/tests/plugins/test_storage_plugins.py +++ b/src/bandersnatch/tests/plugins/test_storage_plugins.py @@ -602,7 +602,9 @@ class BaseStoragePluginTestCase(BasePluginTestCase): web{0}simple web{0}simple{0}foobar web{0}simple{0}foobar{0}index.html -web{0}simple{0}index.html""".format(os.sep).strip() +web{0}simple{0}index.html""".format( + os.sep + ).strip() if sys.platform == "win32": base_find_contents = base_find_contents.replace(".lock\n", "") diff --git a/src/bandersnatch/tests/test_delete.py b/src/bandersnatch/tests/test_delete.py index ee3d138d9..f120a4bb3 100644 --- a/src/bandersnatch/tests/test_delete.py +++ b/src/bandersnatch/tests/test_delete.py @@ -37,7 +37,9 @@ simple{0}cooper{0}index.html simple{0}unittest simple{0}unittest{0}index.html\ -""".format(os.sep) +""".format( + os.sep +) EXPECTED_WEB_AFTER_DELETION = """\ json packages @@ -45,7 +47,9 @@ packages{0}7b pypi simple\ -""".format(os.sep) +""".format( + os.sep +) MOCK_JSON_TEMPLATE = """{ "releases": { "6.9": [ diff --git a/src/bandersnatch/tests/test_filter.py b/src/bandersnatch/tests/test_filter.py index 1529a059e..4932db05c 100644 --- a/src/bandersnatch/tests/test_filter.py +++ b/src/bandersnatch/tests/test_filter.py @@ -38,10 +38,12 @@ def tearDown(self) -> None: self.tempdir = None def test__filter_project_plugins__loads(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = all -""") +""" + ) builtin_plugin_names = [ "blocklist_project", "regex_project", @@ -54,10 +56,12 @@ def test__filter_project_plugins__loads(self) -> None: self.assertIn(name, names) def test__filter_release_plugins__loads(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = all -""") +""" + ) builtin_plugin_names = [ "blocklist_release", "prerelease_release", @@ -71,10 +75,12 @@ def test__filter_release_plugins__loads(self) -> None: self.assertIn(name, names) def test__filter_no_plugin(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = -""") +""" + ) plugins = LoadedFilters().filter_release_plugins() self.assertEqual(len(plugins), 0) @@ -128,7 +134,8 @@ def test_deprecated_keys(self) -> None: assert plugin.blocklist.name == "blocklist" def test__filter_project_blocklist_allowlist__pep503_normalize(self) -> None: - mock_config("""\ + mock_config( + """\ [plugins] enabled = blocklist_project @@ -143,7 +150,8 @@ def test__filter_project_blocklist_allowlist__pep503_normalize(self) -> None: packages = SampleProject trove----classifiers -""") +""" + ) plugins = { plugin.name: plugin for plugin in LoadedFilters().filter_project_plugins() diff --git a/src/bandersnatch/tests/test_mirror.py b/src/bandersnatch/tests/test_mirror.py index a5e13ab1e..5582f20dd 100644 --- a/src/bandersnatch/tests/test_mirror.py +++ b/src/bandersnatch/tests/test_mirror.py @@ -225,8 +225,14 @@ async def test_mirror_empty_master_gets_index(mirror: BandersnatchMirror) -> Non simple simple{0}index.html simple{0}index.v1_html -simple{0}index.v1_json""".format(sep) == utils.find(mirror.webdir) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ +simple{0}index.v1_json""".format( + sep + ) == utils.find( + mirror.webdir + ) + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -236,6 +242,7 @@ async def test_mirror_empty_master_gets_index(mirror: BandersnatchMirror) -> Non """ + ) assert open("status").read() == "0" @@ -270,12 +277,16 @@ async def test_mirror_empty_resume_from_todo_list(mirror: BandersnatchMirror) -> web{0}simple{0}foobar{0}index.v1_json web{0}simple{0}index.html web{0}simple{0}index.v1_html -web{0}simple{0}index.v1_json""".format(sep) +web{0}simple{0}index.v1_json""".format( + sep + ) if WINDOWS: expected = expected.replace(".lock\n", "") assert expected == utils.find(mirror.homedir) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -286,6 +297,7 @@ async def test_mirror_empty_resume_from_todo_list(mirror: BandersnatchMirror) -> foobar
""" + ) assert open("status").read() == "20" @@ -305,7 +317,11 @@ async def test_mirror_sync_package_skip_index(mirror: BandersnatchMirror) -> Non pypi{0}foo{0}json simple{0}foo{0}index.html simple{0}foo{0}index.v1_html -simple{0}foo{0}index.v1_json""".format(sep) == utils.find(mirror.webdir, dirs=False) +simple{0}foo{0}index.v1_json""".format( + sep + ) == utils.find( + mirror.webdir, dirs=False + ) assert open("status", "rb").read() == b"1" @@ -328,8 +344,14 @@ async def test_mirror_sync_package(mirror: BandersnatchMirror) -> None: simple{0}foo{0}index.v1_json simple{0}index.html simple{0}index.v1_html -simple{0}index.v1_json""".format(sep) == utils.find(mirror.webdir, dirs=False) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ +simple{0}index.v1_json""".format( + sep + ) == utils.find( + mirror.webdir, dirs=False + ) + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -340,6 +362,7 @@ async def test_mirror_sync_package(mirror: BandersnatchMirror) -> None: foo
""" + ) assert open("status", "rb").read() == b"1" @@ -362,11 +385,15 @@ async def test_mirror_sync_package_error_no_early_exit( web{0}simple{0}foo{0}index.v1_json web{0}simple{0}index.html web{0}simple{0}index.v1_html -web{0}simple{0}index.v1_json""".format(sep) +web{0}simple{0}index.v1_json""".format( + sep + ) if WINDOWS: expected = expected.replace(".lock\n", "") assert expected == utils.find(mirror.homedir, dirs=False) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -377,6 +404,7 @@ async def test_mirror_sync_package_error_no_early_exit( foo
""" + ) assert open("todo").read() == "1\n" @@ -408,7 +436,11 @@ async def mirror_sync_package_error_early_exit(mirror: BandersnatchMirror) -> No todo web{0}packages{0}any{0}f{0}foo{0}foo.zip web{0}simple{0}foo{0}index.html -web{0}simple{0}index.html""".format(sep) == utils.find(mirror.homedir, dirs=False) +web{0}simple{0}index.html""".format( + sep + ) == utils.find( + mirror.homedir, dirs=False + ) assert open("web{0}simple{0}index.html".format(sep)).read() == "old index" assert open("todo").read() == "1\n" @@ -431,10 +463,14 @@ async def test_mirror_sync_package_with_hash( simple{0}f{0}foo{0}index.v1_json simple{0}index.html simple{0}index.v1_html -simple{0}index.v1_json""".format(sep) == utils.find( +simple{0}index.v1_json""".format( + sep + ) == utils.find( mirror_hash_index.webdir, dirs=False ) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -445,6 +481,7 @@ async def test_mirror_sync_package_with_hash( foo
""" + ) assert open("status").read() == "1" @@ -472,8 +509,14 @@ async def test_mirror_sync_package_download_mirror( simple{0}foo{0}index.v1_json simple{0}index.html simple{0}index.v1_html -simple{0}index.v1_json""".format(sep) == utils.find(mirror.webdir, dirs=False) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ +simple{0}index.v1_json""".format( + sep + ) == utils.find( + mirror.webdir, dirs=False + ) + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -484,6 +527,7 @@ async def test_mirror_sync_package_download_mirror( foo
""" + ) assert open("status", "rb").read() == b"1" @@ -510,8 +554,14 @@ async def test_mirror_sync_package_download_mirror_fallback( simple{0}foo{0}index.v1_json simple{0}index.html simple{0}index.v1_html -simple{0}index.v1_json""".format(sep) == utils.find(mirror.webdir, dirs=False) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ +simple{0}index.v1_json""".format( + sep + ) == utils.find( + mirror.webdir, dirs=False + ) + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -522,6 +572,7 @@ async def test_mirror_sync_package_download_mirror_fallback( foo
""" + ) @pytest.mark.asyncio @@ -554,7 +605,9 @@ async def test_mirror_serial_current_no_sync_of_packages_and_index_page( await mirror.synchronize() assert """\ -last-modified""" == utils.find(mirror.webdir, dirs=False) +last-modified""" == utils.find( + mirror.webdir, dirs=False + ) def test_mirror_json_metadata( @@ -662,7 +715,9 @@ async def test_package_sync_with_release_no_files_syncs_simple_page( # Cross-check that simple directory hashing is disabled. assert not os.path.exists("web/simple/f/foo/index.html") - assert open("web/simple/foo/index.html").read() == """\ + assert ( + open("web/simple/foo/index.html").read() + == """\ @@ -675,7 +730,10 @@ async def test_package_sync_with_release_no_files_syncs_simple_page( \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -686,7 +744,9 @@ async def test_package_sync_with_release_no_files_syncs_simple_page_with_hash( await mirror_hash_index.sync_packages() assert not os.path.exists("web/simple/foo/index.html") - assert open("web/simple/f/foo/index.html").read() == """\ + assert ( + open("web/simple/f/foo/index.html").read() + == """\ @@ -699,7 +759,10 @@ async def test_package_sync_with_release_no_files_syncs_simple_page_with_hash( \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -711,7 +774,9 @@ async def test_package_sync_with_canonical_simple_page( # Cross-check that simple directory hashing is disabled. assert not os.path.exists("web/simple/f/foo/index.html") - assert open("web/simple/foo/index.html").read() == """\ + assert ( + open("web/simple/foo/index.html").read() + == """\ @@ -724,7 +789,10 @@ async def test_package_sync_with_canonical_simple_page( \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -735,7 +803,9 @@ async def test_package_sync_with_canonical_simple_page_with_hash( await mirror_hash_index.sync_packages() assert not os.path.exists("web/simple/foo/index.html") - assert open("web/simple/f/foo/index.html").read() == """\ + assert ( + open("web/simple/f/foo/index.html").read() + == """\ @@ -748,7 +818,10 @@ async def test_package_sync_with_canonical_simple_page_with_hash( \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -759,7 +832,9 @@ async def test_package_sync_with_normalized_simple_page( await mirror.sync_packages() # PEP 503 normalization - assert open("web/simple/foo-bar-thing-other/index.html").read() == """\ + assert ( + open("web/simple/foo-bar-thing-other/index.html").read() + == """\ @@ -772,7 +847,10 @@ async def test_package_sync_with_normalized_simple_page( \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -790,7 +868,9 @@ async def test_package_sync_simple_page_root_uri(mirror: BandersnatchMirror) -> + '">foo.zip
' ) - assert open("web/simple/foo/index.html").read() == """\ + assert ( + open("web/simple/foo/index.html").read() + == """\ @@ -803,7 +883,10 @@ async def test_package_sync_simple_page_root_uri(mirror: BandersnatchMirror) -> \ -""".format(expected_root_uri_hrefs) +""".format( + expected_root_uri_hrefs + ) + ) @pytest.mark.asyncio @@ -812,7 +895,9 @@ async def test_package_sync_simple_page_with_files(mirror: BandersnatchMirror) - await mirror.sync_packages() assert not mirror.errors - assert open("web/simple/foo/index.html").read() == """\ + assert ( + open("web/simple/foo/index.html").read() + == """\ @@ -825,7 +910,10 @@ async def test_package_sync_simple_page_with_files(mirror: BandersnatchMirror) - \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -840,7 +928,9 @@ async def test_package_sync_simple_page_with_existing_dir( # Cross-check that simple directory hashing is disabled. assert not os.path.exists("web/simple/f/foo/index.html") - assert open("web/simple/foo/index.html").read() == """\ + assert ( + open("web/simple/foo/index.html").read() + == """\ @@ -853,7 +943,10 @@ async def test_package_sync_simple_page_with_existing_dir( \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -866,7 +959,9 @@ async def test_package_sync_simple_page_with_existing_dir_with_hash( await mirror_hash_index.sync_packages() assert not os.path.exists("web/simple/foo/index.html") - assert open("web/simple/f/foo/index.html").read() == """\ + assert ( + open("web/simple/f/foo/index.html").read() + == """\ @@ -879,7 +974,10 @@ async def test_package_sync_simple_page_with_existing_dir_with_hash( \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) @pytest.mark.asyncio @@ -1057,7 +1155,9 @@ def record_finished_package(name: str) -> NoReturn: await mirror.sync_packages() - assert Path("web/simple/foo/index.html").open().read() == """\ + assert ( + Path("web/simple/foo/index.html").open().read() + == """\ @@ -1070,7 +1170,10 @@ def record_finished_package(name: str) -> NoReturn: \ -""".format(EXPECTED_REL_HREFS) +""".format( + EXPECTED_REL_HREFS + ) + ) assert mirror.errors diff --git a/src/bandersnatch/tests/test_simple.py b/src/bandersnatch/tests/test_simple.py index 039ee81b9..4ac9de7c1 100644 --- a/src/bandersnatch/tests/test_simple.py +++ b/src/bandersnatch/tests/test_simple.py @@ -96,7 +96,11 @@ def test_json_index_page() -> None: simple{0}foo{0}index.html simple{0}index.html simple{0}index.v1_html -simple{0}index.v1_json""".format(sep) == utils.find(td_path) +simple{0}index.v1_json""".format( + sep + ) == utils.find( + td_path + ) # Check format of JSON assert (simple_dir / "index.v1_json").open( "r" diff --git a/src/bandersnatch/tests/test_sync.py b/src/bandersnatch/tests/test_sync.py index 9017fb72e..90a9e5fcd 100644 --- a/src/bandersnatch/tests/test_sync.py +++ b/src/bandersnatch/tests/test_sync.py @@ -30,9 +30,15 @@ async def test_sync_specific_packages(mirror: BandersnatchMirror) -> None: simple{0}foo{0}index.v1_json simple{0}index.html simple{0}index.v1_html -simple{0}index.v1_json""".format(sep) == utils.find(mirror.webdir, dirs=False) +simple{0}index.v1_json""".format( + sep + ) == utils.find( + mirror.webdir, dirs=False + ) - assert open("web{0}simple{0}index.html".format(sep)).read() == """\ + assert ( + open("web{0}simple{0}index.html".format(sep)).read() + == """\ @@ -43,5 +49,6 @@ async def test_sync_specific_packages(mirror: BandersnatchMirror) -> None: foo
""" + ) # The "sync" method shouldn't update the serial assert open("status", "rb").read() == FAKE_SERIAL diff --git a/src/bandersnatch/tests/test_verify.py b/src/bandersnatch/tests/test_verify.py index 155db5e96..d7aa335a2 100644 --- a/src/bandersnatch/tests/test_verify.py +++ b/src/bandersnatch/tests/test_verify.py @@ -181,7 +181,9 @@ def test_fake_mirror() -> None: web{0}simple{0}bandersnatch web{0}simple{0}bandersnatch{0}index.html web{0}simple{0}black -web{0}simple{0}black{0}index.html""".format(os.sep) +web{0}simple{0}black{0}index.html""".format( + os.sep + ) fm = FakeMirror("_mirror_base_test") assert expected_mirror_layout == find(str(fm.mirror_base), True) fm.clean_up()