diff options
| author | Philip Lorenz <philip.lorenz@bmw.de> | 2025-04-23 17:18:55 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-04-29 13:11:24 +0100 |
| commit | 62c4daafcef2c920607868a0629b9bda59b61951 (patch) | |
| tree | cbb23a073a0b63ec78b9921432f625094771d51d | |
| parent | 67990e1550c80a60db86fb688043902be038dd2d (diff) | |
| download | poky-62c4daafcef2c920607868a0629b9bda59b61951.tar.gz | |
bitbake: tests/fetch: Move commonly used imports to top
Avoid multiple import statements for anything that is used more than
once. Additionally, drop no longer used imports.
(Bitbake rev: 7c74310440f4d6ec47cf5bacf597e18308b3bb20)
Signed-off-by: Philip Lorenz <philip.lorenz@bmw.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 196d93c414..f0c628524c 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
| @@ -7,7 +7,9 @@ | |||
| 7 | # | 7 | # |
| 8 | 8 | ||
| 9 | import contextlib | 9 | import contextlib |
| 10 | import shutil | ||
| 10 | import unittest | 11 | import unittest |
| 12 | import urllib.parse | ||
| 11 | import hashlib | 13 | import hashlib |
| 12 | import tempfile | 14 | import tempfile |
| 13 | import collections | 15 | import collections |
| @@ -1275,7 +1277,6 @@ class FetcherNetworkTest(FetcherTest): | |||
| 1275 | 1277 | ||
| 1276 | class SVNTest(FetcherTest): | 1278 | class SVNTest(FetcherTest): |
| 1277 | def skipIfNoSvn(): | 1279 | def skipIfNoSvn(): |
| 1278 | import shutil | ||
| 1279 | if not shutil.which("svn"): | 1280 | if not shutil.which("svn"): |
| 1280 | return unittest.skip("svn not installed, tests being skipped") | 1281 | return unittest.skip("svn not installed, tests being skipped") |
| 1281 | 1282 | ||
| @@ -1398,8 +1399,6 @@ class TrustedNetworksTest(FetcherTest): | |||
| 1398 | self.assertFalse(bb.fetch.trusted_network(self.d, url)) | 1399 | self.assertFalse(bb.fetch.trusted_network(self.d, url)) |
| 1399 | 1400 | ||
| 1400 | class URLHandle(unittest.TestCase): | 1401 | class URLHandle(unittest.TestCase): |
| 1401 | import urllib.parse | ||
| 1402 | |||
| 1403 | # Quote password as per RFC3986 | 1402 | # Quote password as per RFC3986 |
| 1404 | password = urllib.parse.quote(r"!#$%^&*()-_={}[]\|:?,.<>~`", r"!$&'/()*+,;=") | 1403 | password = urllib.parse.quote(r"!#$%^&*()-_={}[]\|:?,.<>~`", r"!$&'/()*+,;=") |
| 1405 | datatable = { | 1404 | datatable = { |
| @@ -1426,7 +1425,6 @@ class URLHandle(unittest.TestCase): | |||
| 1426 | self.assertEqual(result, v) | 1425 | self.assertEqual(result, v) |
| 1427 | 1426 | ||
| 1428 | def test_encodeurl(self): | 1427 | def test_encodeurl(self): |
| 1429 | import urllib.parse | ||
| 1430 | for k, v in self.datatable.items(): | 1428 | for k, v in self.datatable.items(): |
| 1431 | result = bb.fetch.encodeurl(v) | 1429 | result = bb.fetch.encodeurl(v) |
| 1432 | if result.startswith("file:"): | 1430 | if result.startswith("file:"): |
| @@ -2271,7 +2269,6 @@ class GitShallowTest(FetcherTest): | |||
| 2271 | 2269 | ||
| 2272 | class GitLfsTest(FetcherTest): | 2270 | class GitLfsTest(FetcherTest): |
| 2273 | def skipIfNoGitLFS(): | 2271 | def skipIfNoGitLFS(): |
| 2274 | import shutil | ||
| 2275 | if not shutil.which('git-lfs'): | 2272 | if not shutil.which('git-lfs'): |
| 2276 | return unittest.skip('git-lfs not installed') | 2273 | return unittest.skip('git-lfs not installed') |
| 2277 | return lambda f: f | 2274 | return lambda f: f |
| @@ -2391,8 +2388,6 @@ class GitLfsTest(FetcherTest): | |||
| 2391 | 2388 | ||
| 2392 | @skipIfNoGitLFS() | 2389 | @skipIfNoGitLFS() |
| 2393 | def test_lfs_enabled(self): | 2390 | def test_lfs_enabled(self): |
| 2394 | import shutil | ||
| 2395 | |||
| 2396 | uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir | 2391 | uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir |
| 2397 | self.d.setVar('SRC_URI', uri) | 2392 | self.d.setVar('SRC_URI', uri) |
| 2398 | 2393 | ||
| @@ -2403,8 +2398,6 @@ class GitLfsTest(FetcherTest): | |||
| 2403 | 2398 | ||
| 2404 | @skipIfNoGitLFS() | 2399 | @skipIfNoGitLFS() |
| 2405 | def test_lfs_disabled(self): | 2400 | def test_lfs_disabled(self): |
| 2406 | import shutil | ||
| 2407 | |||
| 2408 | uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir | 2401 | uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir |
| 2409 | self.d.setVar('SRC_URI', uri) | 2402 | self.d.setVar('SRC_URI', uri) |
| 2410 | 2403 | ||
| @@ -2414,8 +2407,6 @@ class GitLfsTest(FetcherTest): | |||
| 2414 | fetcher.unpack(self.d.getVar('WORKDIR')) | 2407 | fetcher.unpack(self.d.getVar('WORKDIR')) |
| 2415 | 2408 | ||
| 2416 | def test_lfs_enabled_not_installed(self): | 2409 | def test_lfs_enabled_not_installed(self): |
| 2417 | import shutil | ||
| 2418 | |||
| 2419 | uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir | 2410 | uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir |
| 2420 | self.d.setVar('SRC_URI', uri) | 2411 | self.d.setVar('SRC_URI', uri) |
| 2421 | 2412 | ||
| @@ -2436,8 +2427,6 @@ class GitLfsTest(FetcherTest): | |||
| 2436 | ud.method._find_git_lfs = old_find_git_lfs | 2427 | ud.method._find_git_lfs = old_find_git_lfs |
| 2437 | 2428 | ||
| 2438 | def test_lfs_disabled_not_installed(self): | 2429 | def test_lfs_disabled_not_installed(self): |
| 2439 | import shutil | ||
| 2440 | |||
| 2441 | uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir | 2430 | uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir |
| 2442 | self.d.setVar('SRC_URI', uri) | 2431 | self.d.setVar('SRC_URI', uri) |
| 2443 | 2432 | ||
| @@ -2611,7 +2600,6 @@ class CrateTest(FetcherTest): | |||
| 2611 | 2600 | ||
| 2612 | class NPMTest(FetcherTest): | 2601 | class NPMTest(FetcherTest): |
| 2613 | def skipIfNoNpm(): | 2602 | def skipIfNoNpm(): |
| 2614 | import shutil | ||
| 2615 | if not shutil.which('npm'): | 2603 | if not shutil.which('npm'): |
| 2616 | return unittest.skip('npm not installed') | 2604 | return unittest.skip('npm not installed') |
| 2617 | return lambda f: f | 2605 | return lambda f: f |
| @@ -3294,7 +3282,6 @@ class FetchPremirroronlyNetworkTest(FetcherTest): | |||
| 3294 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") | 3282 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") |
| 3295 | 3283 | ||
| 3296 | def make_git_repo(self): | 3284 | def make_git_repo(self): |
| 3297 | import shutil | ||
| 3298 | self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz" | 3285 | self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz" |
| 3299 | os.makedirs(self.clonedir) | 3286 | os.makedirs(self.clonedir) |
| 3300 | self.git("clone --bare {}".format(self.recipe_url), self.clonedir) | 3287 | self.git("clone --bare {}".format(self.recipe_url), self.clonedir) |
| @@ -3324,7 +3311,6 @@ class FetchPremirroronlyMercurialTest(FetcherTest): | |||
| 3324 | the test covers also basic hg:// clone (see fetch_and_create_tarball | 3311 | the test covers also basic hg:// clone (see fetch_and_create_tarball |
| 3325 | """ | 3312 | """ |
| 3326 | def skipIfNoHg(): | 3313 | def skipIfNoHg(): |
| 3327 | import shutil | ||
| 3328 | if not shutil.which('hg'): | 3314 | if not shutil.which('hg'): |
| 3329 | return unittest.skip('Mercurial not installed') | 3315 | return unittest.skip('Mercurial not installed') |
| 3330 | return lambda f: f | 3316 | return lambda f: f |
| @@ -3380,7 +3366,6 @@ class FetchPremirroronlyBrokenTarball(FetcherTest): | |||
| 3380 | targz.write("This is not tar.gz file!") | 3366 | targz.write("This is not tar.gz file!") |
| 3381 | 3367 | ||
| 3382 | def test_mirror_broken_download(self): | 3368 | def test_mirror_broken_download(self): |
| 3383 | import sys | ||
| 3384 | self.d.setVar("SRCREV", "0"*40) | 3369 | self.d.setVar("SRCREV", "0"*40) |
| 3385 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) | 3370 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 3386 | with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs: | 3371 | with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs: |
