[v2,2/3] tests/fetch: deduplicate local git testing code

Message ID 20210413150251.1969-2-henning.schild@siemens.com
State Superseded, archived
Headers show
Series [v2,1/3] fetch/git: add support for disabling shared clones on unpack | expand

Commit Message

Henning Schild April 13, 2021, 7:02 a.m. UTC
Purely cosmetic change that probably improves the code.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
---
 lib/bb/tests/fetch.py | 33 +++++++--------------------------
 1 file changed, 7 insertions(+), 26 deletions(-)

Comments

Richard Purdie April 13, 2021, 1:37 p.m. UTC | #1
On Tue, 2021-04-13 at 17:02 +0200, Henning Schild wrote:
> Purely cosmetic change that probably improves the code.
> 
> Signed-off-by: Henning Schild <henning.schild@siemens.com>
> ---
>  lib/bb/tests/fetch.py | 33 +++++++--------------------------
>  1 file changed, 7 insertions(+), 26 deletions(-)

The patches look good but could you rebase+resend against master-next 
please? We're just sorting the current release out so there is a small 
queue and yours conflicts with another in the queue there.

Cheers,

Richard
Henning Schild April 13, 2021, 10:33 p.m. UTC | #2
Am Tue, 13 Apr 2021 22:37:52 +0100
schrieb Richard Purdie <richard.purdie@linuxfoundation.org>:

> On Tue, 2021-04-13 at 17:02 +0200, Henning Schild wrote:
> > Purely cosmetic change that probably improves the code.
> > 
> > Signed-off-by: Henning Schild <henning.schild@siemens.com>
> > ---
> >  lib/bb/tests/fetch.py | 33 +++++++--------------------------
> >  1 file changed, 7 insertions(+), 26 deletions(-)  
> 
> The patches look good but could you rebase+resend against master-next 
> please? We're just sorting the current release out so there is a
> small queue and yours conflicts with another in the queue there.

Done in v3.

regards,
Henning

> Cheers,
> 
> Richard
>

Patch

diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index ddf6e97439b5..76797473db8a 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -673,7 +673,7 @@  class FetcherLocalTest(FetcherTest):
         with self.assertRaises(bb.fetch2.UnpackError):
             self.fetchUnpack(['file://a;subdir=/bin/sh'])
 
-    def test_local_gitfetch_usehead(self):
+    def dummyGitTest(self, suffix):
         # Create dummy local Git repo
         src_dir = tempfile.mkdtemp(dir=self.tempdir,
                                    prefix='gitfetch_localusehead_')
@@ -690,7 +690,7 @@  class FetcherLocalTest(FetcherTest):
 
         # Fetch and check revision
         self.d.setVar("SRCREV", "AUTOINC")
-        url = "git://" + src_dir + ";protocol=file;usehead=1"
+        url = "git://" + src_dir + ";protocol=file;" + suffix
         fetcher = bb.fetch.Fetch([url], self.d)
         fetcher.download()
         fetcher.unpack(self.unpackdir)
@@ -699,31 +699,12 @@  class FetcherLocalTest(FetcherTest):
         unpack_rev = stdout[0].strip()
         self.assertEqual(orig_rev, unpack_rev)
 
-    def test_local_gitfetch_usehead_withname(self):
-        # Create dummy local Git repo
-        src_dir = tempfile.mkdtemp(dir=self.tempdir,
-                                   prefix='gitfetch_localusehead_')
-        src_dir = os.path.abspath(src_dir)
-        bb.process.run("git init", cwd=src_dir)
-        bb.process.run("git commit --allow-empty -m'Dummy commit'",
-                       cwd=src_dir)
-        # Use other branch than master
-        bb.process.run("git checkout -b my-devel", cwd=src_dir)
-        bb.process.run("git commit --allow-empty -m'Dummy commit 2'",
-                       cwd=src_dir)
-        stdout = bb.process.run("git rev-parse HEAD", cwd=src_dir)
-        orig_rev = stdout[0].strip()
 
-        # Fetch and check revision
-        self.d.setVar("SRCREV", "AUTOINC")
-        url = "git://" + src_dir + ";protocol=file;usehead=1;name=newName"
-        fetcher = bb.fetch.Fetch([url], self.d)
-        fetcher.download()
-        fetcher.unpack(self.unpackdir)
-        stdout = bb.process.run("git rev-parse HEAD",
-                                cwd=os.path.join(self.unpackdir, 'git'))
-        unpack_rev = stdout[0].strip()
-        self.assertEqual(orig_rev, unpack_rev)
+    def test_local_gitfetch_usehead(self):
+        self.dummyGitTest("usehead=1")
+
+    def test_local_gitfetch_usehead_withname(self):
+        self.dummyGitTest("usehead=1;name=newName")
 
 class FetcherNoNetworkTest(FetcherTest):
     def setUp(self):