diff mbox series

[RFC,11/21] tests: fetch: adapt style in npm(sw) class

Message ID 20241220112613.22647-12-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series Concept for tightly coupled package manager (Node.js, Go, Rust) | expand

Commit Message

Stefan Herbrechtsmeier Dec. 20, 2024, 11:26 a.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

 lib/bb/tests/fetch.py | 348 +++++++++++++++++++++---------------------
 1 file changed, 174 insertions(+), 174 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 6b8e3e060..934b96cac 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -2620,47 +2620,47 @@  class CrateTest(FetcherTest):
 class NPMTest(FetcherTest):
     def skipIfNoNpm():
         import shutil
-        if not shutil.which('npm'):
-            return unittest.skip('npm not installed')
+        if not shutil.which("npm"):
+            return unittest.skip("npm not installed")
         return lambda f: f
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         fetcher = bb.fetch.Fetch(urls, self.d)
         ud = fetcher.ud[fetcher.urls[0]]
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
-        self.assertTrue(os.path.exists(ud.localpath + '.done'))
+        self.assertTrue(os.path.exists(ud.localpath + ".done"))
         self.assertTrue(os.path.exists(ud.resolvefile))
         fetcher.unpack(self.unpackdir)
-        unpackdir = os.path.join(self.unpackdir, 'npm')
-        self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
+        unpackdir = os.path.join(self.unpackdir, "npm")
+        self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json")))
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_bad_checksum(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         # Fetch once to get a tarball
         fetcher = bb.fetch.Fetch(urls, self.d)
         ud = fetcher.ud[fetcher.urls[0]]
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
         # Modify the tarball
-        bad = b'bad checksum'
-        with open(ud.localpath, 'wb') as f:
+        bad = b"bad checksum"
+        with open(ud.localpath, "wb") as f:
             f.write(bad)
         # Verify that the tarball is fetched again
         fetcher.download()
         badsum = hashlib.sha512(bad).hexdigest()
-        self.assertTrue(os.path.exists(ud.localpath + '_bad-checksum_' + badsum))
+        self.assertTrue(os.path.exists(ud.localpath + "_bad-checksum_" + badsum))
         self.assertTrue(os.path.exists(ud.localpath))
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_premirrors(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         # Fetch once to get a tarball
         fetcher = bb.fetch.Fetch(urls, self.d)
         ud = fetcher.ud[fetcher.urls[0]]
@@ -2668,17 +2668,17 @@  class NPMTest(FetcherTest):
         self.assertTrue(os.path.exists(ud.localpath))
 
         # Setup the mirror by renaming the download directory
-        mirrordir = os.path.join(self.tempdir, 'mirror')
+        mirrordir = os.path.join(self.tempdir, "mirror")
         bb.utils.rename(self.dldir, mirrordir)
         os.mkdir(self.dldir)
 
         # Configure the premirror to be used
-        self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/npm2' % mirrordir)
-        self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
+        self.d.setVar("PREMIRRORS", "https?$://.*/.* file://%s/npm2" % mirrordir)
+        self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
 
         # Fetch again
         self.assertFalse(os.path.exists(ud.localpath))
-        # The npm fetcher doesn't handle that the .resolved file disappears
+        # The npm fetcher doesn"t handle that the .resolved file disappears
         # while the fetcher object exists, which it does when we rename the
         # download directory to "mirror" above. Thus we need a new fetcher to go
         # with the now empty download directory.
@@ -2690,19 +2690,19 @@  class NPMTest(FetcherTest):
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_premirrors_with_specified_filename(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         # Fetch once to get a tarball
         fetcher = bb.fetch.Fetch(urls, self.d)
         ud = fetcher.ud[fetcher.urls[0]]
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
         # Setup the mirror
-        mirrordir = os.path.join(self.tempdir, 'mirror')
+        mirrordir = os.path.join(self.tempdir, "mirror")
         bb.utils.mkdirhier(mirrordir)
         mirrorfilename = os.path.join(mirrordir, os.path.basename(ud.localpath))
         os.replace(ud.localpath, mirrorfilename)
-        self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s' % mirrorfilename)
-        self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
+        self.d.setVar("PREMIRRORS", "https?$://.*/.* file://%s" % mirrorfilename)
+        self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
         # Fetch again
         self.assertFalse(os.path.exists(ud.localpath))
         fetcher.download()
@@ -2712,22 +2712,22 @@  class NPMTest(FetcherTest):
     @skipIfNoNetwork()
     def test_npm_mirrors(self):
         # Fetch once to get a tarball
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         fetcher = bb.fetch.Fetch(urls, self.d)
         ud = fetcher.ud[fetcher.urls[0]]
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
         # Setup the mirror
-        mirrordir = os.path.join(self.tempdir, 'mirror')
+        mirrordir = os.path.join(self.tempdir, "mirror")
         bb.utils.mkdirhier(mirrordir)
         os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
-        self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
+        self.d.setVar("MIRRORS", "https?$://.*/.* file://%s/" % mirrordir)
         # Update the resolved url to an invalid url
-        with open(ud.resolvefile, 'r') as f:
+        with open(ud.resolvefile, "r") as f:
             url = f.read()
         uri = URI(url)
-        uri.path = '/invalid'
-        with open(ud.resolvefile, 'w') as f:
+        uri.path = "/invalid"
+        with open(ud.resolvefile, "w") as f:
             f.write(str(uri))
         # Fetch again
         self.assertFalse(os.path.exists(ud.localpath))
@@ -2737,17 +2737,17 @@  class NPMTest(FetcherTest):
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_destsuffix_downloadfilename(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz"]
         fetcher = bb.fetch.Fetch(urls, self.d)
         fetcher.download()
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'foo-bar.tgz')))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/foo-bar.tgz")))
         fetcher.unpack(self.unpackdir)
-        unpackdir = os.path.join(self.unpackdir, 'foo', 'bar')
-        self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
+        unpackdir = os.path.join(self.unpackdir, "foo", "bar")
+        self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json")))
 
     def test_npm_no_network_no_tarball(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
-        self.d.setVar('BB_NO_NETWORK', '1')
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
+        self.d.setVar("BB_NO_NETWORK", "1")
         fetcher = bb.fetch.Fetch(urls, self.d)
         with self.assertRaises(bb.fetch2.NetworkAccess):
             fetcher.download()
@@ -2755,42 +2755,42 @@  class NPMTest(FetcherTest):
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_no_network_with_tarball(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         # Fetch once to get a tarball
         fetcher = bb.fetch.Fetch(urls, self.d)
         fetcher.download()
         # Disable network access
-        self.d.setVar('BB_NO_NETWORK', '1')
+        self.d.setVar("BB_NO_NETWORK", "1")
         # Fetch again
         fetcher.download()
         fetcher.unpack(self.unpackdir)
-        unpackdir = os.path.join(self.unpackdir, 'npm')
-        self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
+        unpackdir = os.path.join(self.unpackdir, "npm")
+        self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json")))
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_registry_alternate(self):
-        urls = ['npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         fetcher = bb.fetch.Fetch(urls, self.d)
         fetcher.download()
         fetcher.unpack(self.unpackdir)
-        unpackdir = os.path.join(self.unpackdir, 'npm')
-        self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
+        unpackdir = os.path.join(self.unpackdir, "npm")
+        self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json")))
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_version_latest(self):
-        url = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest']
+        url = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest"]
         fetcher = bb.fetch.Fetch(urls, self.d)
         fetcher.download()
         fetcher.unpack(self.unpackdir)
-        unpackdir = os.path.join(self.unpackdir, 'npm')
-        self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
+        unpackdir = os.path.join(self.unpackdir, "npm")
+        self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json")))
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_registry_invalid(self):
-        urls = ['npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         fetcher = bb.fetch.Fetch(urls, self.d)
         with self.assertRaises(bb.fetch2.FetchError):
             fetcher.download()
@@ -2798,7 +2798,7 @@  class NPMTest(FetcherTest):
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_package_invalid(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0"]
         fetcher = bb.fetch.Fetch(urls, self.d)
         with self.assertRaises(bb.fetch2.FetchError):
             fetcher.download()
@@ -2806,145 +2806,145 @@  class NPMTest(FetcherTest):
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_version_invalid(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid"]
         with self.assertRaises(bb.fetch2.ParameterError):
             fetcher = bb.fetch.Fetch(urls, self.d)
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_registry_none(self):
-        urls = ['npm://;package=@savoirfairelinux/node-server-example;version=1.0.0']
+        urls = ["npm://;package=@savoirfairelinux/node-server-example;version=1.0.0"]
         with self.assertRaises(bb.fetch2.MalformedUrl):
             fetcher = bb.fetch.Fetch(urls, self.d)
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_package_none(self):
-        urls = ['npm://registry.npmjs.org;version=1.0.0']
+        urls = ["npm://registry.npmjs.org;version=1.0.0"]
         with self.assertRaises(bb.fetch2.MissingParameterError):
             fetcher = bb.fetch.Fetch(urls, self.d)
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npm_version_none(self):
-        urls = ['npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example']
+        urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example"]
         with self.assertRaises(bb.fetch2.MissingParameterError):
             fetcher = bb.fetch.Fetch(urls, self.d)
 
     def create_shrinkwrap_file(self, data):
         import json
-        datadir = os.path.join(self.tempdir, 'data')
-        swfile = os.path.join(datadir, 'npm-shrinkwrap.json')
+        datadir = os.path.join(self.tempdir, "data")
+        swfile = os.path.join(datadir, "npm-shrinkwrap.json")
         bb.utils.mkdirhier(datadir)
-        with open(swfile, 'w') as f:
+        with open(swfile, "w") as f:
             json.dump(data, f)
         return swfile
 
     @skipIfNoNetwork()
     def test_npmsw(self):
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=',
-                    'dependencies': {
-                        'content-type': "1.0.4"
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=",
+                    "dependencies": {
+                        "content-type": "1.0.4"
                     }
                 },
-                'node_modules/array-flatten/node_modules/content-type': {
-                    'version': '1.0.4',
-                    'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
-                    'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
-                    'dependencies': {
-                        'cookie': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
+                "node_modules/array-flatten/node_modules/content-type": {
+                    "version": "1.0.4",
+                    "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
+                    "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
+                    "dependencies": {
+                        "cookie": "git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09"
                     }
                 },
-                'node_modules/array-flatten/node_modules/content-type/node_modules/cookie': {
-                    'resolved': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
+                "node_modules/array-flatten/node_modules/content-type/node_modules/cookie": {
+                    "resolved": "git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09"
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/array-flatten-1.1.1.tgz")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/content-type-1.0.4.tgz")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/github.com.jshttp.cookie.git")))
         fetcher.unpack(self.unpackdir)
-        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm-shrinkwrap.json')))
-        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'package.json')))
-        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json')))
-        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json')))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "npm-shrinkwrap.json")))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "node_modules/array-flatten/package.json")))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "node_modules/array-flatten/node_modules/content-type/package.json")))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "node_modules/array-flatten/node_modules/content-type/node_modules/cookie/package.json")))
 
     @skipIfNoNetwork()
     def test_npmsw_git(self):
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/cookie': {
-                    'resolved': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09'
+            "packages": {
+                "node_modules/cookie": {
+                    "resolved": "git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09"
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "git2/github.com.jshttp.cookie.git")))
 
     @skipIfNoNetwork()
     def test_npmsw_dev(self):
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 },
-                'node_modules/content-type': {
-                    'version': '1.0.4',
-                    'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
-                    'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
-                    'dev': True
+                "node_modules/content-type": {
+                    "version": "1.0.4",
+                    "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
+                    "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
+                    "dev": True
                 }
             }
         })
         # Fetch with dev disabled
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
-        self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/array-flatten-1.1.1.tgz")))
+        self.assertFalse(os.path.exists(os.path.join(self.dldir, "npm2/content-type-1.0.4.tgz")))
         # Fetch with dev enabled
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';dev=1'], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile + ";dev=1"], self.d)
         fetcher.download()
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/array-flatten-1.1.1.tgz")))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/content-type-1.0.4.tgz")))
 
     @skipIfNoNetwork()
     def test_npmsw_destsuffix(self):
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';destsuffix=foo/bar'], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile + ";destsuffix=foo/bar"], self.d)
         fetcher.download()
         fetcher.unpack(self.unpackdir)
-        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'foo', 'bar', 'node_modules', 'array-flatten', 'package.json')))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "foo/bar/node_modules/array-flatten/package.json")))
 
     def test_npmsw_no_network_no_tarball(self):
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 }
             }
         })
-        self.d.setVar('BB_NO_NETWORK', '1')
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        self.d.setVar("BB_NO_NETWORK", "1")
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         with self.assertRaises(bb.fetch2.NetworkAccess):
             fetcher.download()
 
@@ -2952,112 +2952,112 @@  class NPMTest(FetcherTest):
     @skipIfNoNetwork()
     def test_npmsw_no_network_with_tarball(self):
         # Fetch once to get a tarball
-        fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
+        fetcher = bb.fetch.Fetch(["npm://registry.npmjs.org;package=array-flatten;version=1.1.1"], self.d)
         fetcher.download()
         # Disable network access
-        self.d.setVar('BB_NO_NETWORK', '1')
+        self.d.setVar("BB_NO_NETWORK", "1")
         # Fetch again
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
         fetcher.unpack(self.unpackdir)
-        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'node_modules', 'array-flatten', 'package.json')))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "node_modules/array-flatten/package.json")))
 
     @skipIfNoNetwork()
     def test_npmsw_npm_reusability(self):
         # Fetch once with npmsw
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
         # Disable network access
-        self.d.setVar('BB_NO_NETWORK', '1')
+        self.d.setVar("BB_NO_NETWORK", "1")
         # Fetch again with npm
-        fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
+        fetcher = bb.fetch.Fetch(["npm://registry.npmjs.org;package=array-flatten;version=1.1.1"], self.d)
         fetcher.download()
         fetcher.unpack(self.unpackdir)
-        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json')))
+        self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "npm/package.json")))
 
     @skipIfNoNetwork()
     def test_npmsw_bad_checksum(self):
         # Try to fetch with bad checksum
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg="
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         with self.assertRaises(bb.fetch2.FetchError):
             fetcher.download()
         # Fetch correctly to get a tarball
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
-        localpath = os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')
+        localpath = os.path.join(self.dldir, "npm2/array-flatten-1.1.1.tgz")
         self.assertTrue(os.path.exists(localpath))
         # Modify the tarball
-        bad = b'bad checksum'
-        with open(localpath, 'wb') as f:
+        bad = b"bad checksum"
+        with open(localpath, "wb") as f:
             f.write(bad)
         # Verify that the tarball is fetched again
         fetcher.download()
         badsum = hashlib.sha1(bad).hexdigest()
-        self.assertTrue(os.path.exists(localpath + '_bad-checksum_' + badsum))
+        self.assertTrue(os.path.exists(localpath + "_bad-checksum_" + badsum))
         self.assertTrue(os.path.exists(localpath))
 
     @skipIfNoNpm()
     @skipIfNoNetwork()
     def test_npmsw_premirrors(self):
         # Fetch once to get a tarball
-        fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
+        fetcher = bb.fetch.Fetch(["npm://registry.npmjs.org;package=array-flatten;version=1.1.1"], self.d)
         ud = fetcher.ud[fetcher.urls[0]]
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
         # Setup the mirror
-        mirrordir = os.path.join(self.tempdir, 'mirror')
+        mirrordir = os.path.join(self.tempdir, "mirror")
         bb.utils.mkdirhier(mirrordir)
         os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
-        self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
-        self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
+        self.d.setVar("PREMIRRORS", "https?$://.*/.* file://%s/" % mirrordir)
+        self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
         # Fetch again
         self.assertFalse(os.path.exists(ud.localpath))
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
 
@@ -3065,51 +3065,51 @@  class NPMTest(FetcherTest):
     @skipIfNoNetwork()
     def test_npmsw_mirrors(self):
         # Fetch once to get a tarball
-        fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d)
+        fetcher = bb.fetch.Fetch(["npm://registry.npmjs.org;package=array-flatten;version=1.1.1"], self.d)
         ud = fetcher.ud[fetcher.urls[0]]
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
         # Setup the mirror
-        mirrordir = os.path.join(self.tempdir, 'mirror')
+        mirrordir = os.path.join(self.tempdir, "mirror")
         bb.utils.mkdirhier(mirrordir)
         os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
-        self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir)
+        self.d.setVar("MIRRORS", "https?$://.*/.* file://%s/" % mirrordir)
         # Fetch again with invalid url
         self.assertFalse(os.path.exists(ud.localpath))
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://invalid',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://invalid",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
         self.assertTrue(os.path.exists(ud.localpath))
 
     @skipIfNoNetwork()
     def test_npmsw_bundled(self):
         swfile = self.create_shrinkwrap_file({
-            'packages': {
-                'node_modules/array-flatten': {
-                    'version': '1.1.1',
-                    'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz',
-                    'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI='
+            "packages": {
+                "node_modules/array-flatten": {
+                    "version": "1.1.1",
+                    "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+                    "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
                 },
-                'node_modules/content-type': {
-                    'version': '1.0.4',
-                    'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz',
-                    'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==',
-                    'inBundle': True
+                "node_modules/content-type": {
+                    "version": "1.0.4",
+                    "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
+                    "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
+                    "inBundle": True
                 }
             }
         })
-        fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
+        fetcher = bb.fetch.Fetch(["npmsw://" + swfile], self.d)
         fetcher.download()
-        self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz')))
-        self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz')))
+        self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/array-flatten-1.1.1.tgz")))
+        self.assertFalse(os.path.exists(os.path.join(self.dldir, "npm2/content-type-1.0.4.tgz")))
 
 class GitSharedTest(FetcherTest):
     def setUp(self):