summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/fetch.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r--bitbake/lib/bb/tests/fetch.py73
1 files changed, 50 insertions, 23 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index f0c628524c..c77725190f 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -9,6 +9,7 @@
9import contextlib 9import contextlib
10import shutil 10import shutil
11import unittest 11import unittest
12import unittest.mock
12import urllib.parse 13import urllib.parse
13import hashlib 14import hashlib
14import tempfile 15import tempfile
@@ -2292,12 +2293,18 @@ class GitLfsTest(FetcherTest):
2292 self.git_init(cwd=self.srcdir) 2293 self.git_init(cwd=self.srcdir)
2293 self.commit_file('.gitattributes', '*.mp3 filter=lfs -text') 2294 self.commit_file('.gitattributes', '*.mp3 filter=lfs -text')
2294 2295
2295 def commit_file(self, filename, content): 2296 def commit(self, *, cwd=None):
2296 with open(os.path.join(self.srcdir, filename), "w") as f: 2297 cwd = cwd or self.srcdir
2298 self.git(["commit", "-m", "Change"], cwd=cwd)
2299 return self.git(["rev-parse", "HEAD"], cwd=cwd).strip()
2300
2301 def commit_file(self, filename, content, *, cwd=None):
2302 cwd = cwd or self.srcdir
2303
2304 with open(os.path.join(cwd, filename), "w") as f:
2297 f.write(content) 2305 f.write(content)
2298 self.git(["add", filename], cwd=self.srcdir) 2306 self.git(["add", filename], cwd=cwd)
2299 self.git(["commit", "-m", "Change"], cwd=self.srcdir) 2307 return self.commit(cwd=cwd)
2300 return self.git(["rev-parse", "HEAD"], cwd=self.srcdir).strip()
2301 2308
2302 def fetch(self, uri=None, download=True): 2309 def fetch(self, uri=None, download=True):
2303 uris = self.d.getVar('SRC_URI').split() 2310 uris = self.d.getVar('SRC_URI').split()
@@ -2406,6 +2413,21 @@ class GitLfsTest(FetcherTest):
2406 fetcher, ud = self.fetch() 2413 fetcher, ud = self.fetch()
2407 fetcher.unpack(self.d.getVar('WORKDIR')) 2414 fetcher.unpack(self.d.getVar('WORKDIR'))
2408 2415
2416 @skipIfNoGitLFS()
2417 def test_lfs_enabled_not_installed_during_unpack(self):
2418 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2419 self.d.setVar('SRC_URI', uri)
2420
2421 # Careful: suppress initial attempt at downloading
2422 fetcher, ud = self.fetch(uri=None, download=False)
2423
2424 fetcher.download()
2425 # If git-lfs cannot be found, the unpack should throw an error
2426 with self.assertRaises(bb.fetch2.FetchError):
2427 with unittest.mock.patch("shutil.which", return_value=None):
2428 shutil.rmtree(self.gitdir, ignore_errors=True)
2429 fetcher.unpack(self.d.getVar('WORKDIR'))
2430
2409 def test_lfs_enabled_not_installed(self): 2431 def test_lfs_enabled_not_installed(self):
2410 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir 2432 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2411 self.d.setVar('SRC_URI', uri) 2433 self.d.setVar('SRC_URI', uri)
@@ -2413,18 +2435,10 @@ class GitLfsTest(FetcherTest):
2413 # Careful: suppress initial attempt at downloading 2435 # Careful: suppress initial attempt at downloading
2414 fetcher, ud = self.fetch(uri=None, download=False) 2436 fetcher, ud = self.fetch(uri=None, download=False)
2415 2437
2416 # Artificially assert that git-lfs is not installed, so 2438 # If git-lfs cannot be found, the download should throw an error
2417 # we can verify a failure to unpack in it's absence. 2439 with unittest.mock.patch("shutil.which", return_value=None):
2418 old_find_git_lfs = ud.method._find_git_lfs
2419 try:
2420 # If git-lfs cannot be found, the unpack should throw an error
2421 with self.assertRaises(bb.fetch2.FetchError): 2440 with self.assertRaises(bb.fetch2.FetchError):
2422 fetcher.download() 2441 fetcher.download()
2423 ud.method._find_git_lfs = lambda d: False
2424 shutil.rmtree(self.gitdir, ignore_errors=True)
2425 fetcher.unpack(self.d.getVar('WORKDIR'))
2426 finally:
2427 ud.method._find_git_lfs = old_find_git_lfs
2428 2442
2429 def test_lfs_disabled_not_installed(self): 2443 def test_lfs_disabled_not_installed(self):
2430 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir 2444 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
@@ -2433,17 +2447,30 @@ class GitLfsTest(FetcherTest):
2433 # Careful: suppress initial attempt at downloading 2447 # Careful: suppress initial attempt at downloading
2434 fetcher, ud = self.fetch(uri=None, download=False) 2448 fetcher, ud = self.fetch(uri=None, download=False)
2435 2449
2436 # Artificially assert that git-lfs is not installed, so 2450 # Even if git-lfs cannot be found, the download / unpack should be successful
2437 # we can verify a failure to unpack in it's absence. 2451 with unittest.mock.patch("shutil.which", return_value=None):
2438 old_find_git_lfs = ud.method._find_git_lfs 2452 fetcher.download()
2439 try: 2453 shutil.rmtree(self.gitdir, ignore_errors=True)
2440 # Even if git-lfs cannot be found, the unpack should be successful 2454 fetcher.unpack(self.d.getVar('WORKDIR'))
2455
2456 def test_lfs_enabled_not_installed_but_not_needed(self):
2457 srcdir = os.path.join(self.tempdir, "emptygit")
2458 bb.utils.mkdirhier(srcdir)
2459 self.git_init(srcdir)
2460 self.commit_file("test", "test content", cwd=srcdir)
2461
2462 uri = 'git://%s;protocol=file;lfs=1;branch=master' % srcdir
2463 self.d.setVar('SRC_URI', uri)
2464
2465 # Careful: suppress initial attempt at downloading
2466 fetcher, ud = self.fetch(uri=None, download=False)
2467
2468 # It shouldnt't matter that git-lfs cannot be found as the repository configuration does not
2469 # specify any LFS filters.
2470 with unittest.mock.patch("shutil.which", return_value=None):
2441 fetcher.download() 2471 fetcher.download()
2442 ud.method._find_git_lfs = lambda d: False
2443 shutil.rmtree(self.gitdir, ignore_errors=True) 2472 shutil.rmtree(self.gitdir, ignore_errors=True)
2444 fetcher.unpack(self.d.getVar('WORKDIR')) 2473 fetcher.unpack(self.d.getVar('WORKDIR'))
2445 finally:
2446 ud.method._find_git_lfs = old_find_git_lfs
2447 2474
2448class GitURLWithSpacesTest(FetcherTest): 2475class GitURLWithSpacesTest(FetcherTest):
2449 test_git_urls = { 2476 test_git_urls = {