public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/tests/simple/
@ 2021-03-28 19:53 Zac Medico
  0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2021-03-28 19:53 UTC (permalink / raw
  To: gentoo-commits

commit:     c9ffa3aa5fab400a3232cfa46c2e194d874ba649
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 28 19:42:25 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Mar 28 19:52:04 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c9ffa3aa

SimpleRepomanTestCase: use asyncio

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 repoman/lib/repoman/tests/simple/test_simple.py | 89 ++++++++++++++++++-------
 1 file changed, 66 insertions(+), 23 deletions(-)

diff --git a/repoman/lib/repoman/tests/simple/test_simple.py b/repoman/lib/repoman/tests/simple/test_simple.py
index 2448bb117..a4cdf5207 100644
--- a/repoman/lib/repoman/tests/simple/test_simple.py
+++ b/repoman/lib/repoman/tests/simple/test_simple.py
@@ -2,15 +2,14 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import subprocess
-import sys
 import time
 
 from repoman._portage import portage
 from portage import os
-from portage import _unicode_decode
 from portage.process import find_binary
 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
 from portage.util import ensure_dirs
+from portage.util.futures import asyncio
 
 # pylint: disable=ungrouped-imports
 from repoman import REPOMAN_BASE_PATH
@@ -169,6 +168,39 @@ class SimpleRepomanTestCase(TestCase):
 
 		playground = ResolverPlayground(ebuilds=ebuilds,
 			profile=profile, repo_configs=repo_configs, debug=debug)
+
+		loop = asyncio._wrap_loop()
+		loop.run_until_complete(
+			asyncio.ensure_future(
+				self._async_test_simple(
+					playground,
+					metadata_xml_files,
+					profiles,
+					profile,
+					licenses,
+					arch_list,
+					use_desc,
+					metadata_xsd,
+					copyright_header,
+					debug,
+				),
+				loop=loop,
+			)
+		)
+
+	async def _async_test_simple(
+		self,
+		playground,
+		metadata_xml_files,
+		profiles,
+		profile,
+		licenses,
+		arch_list,
+		use_desc,
+		metadata_xsd,
+		copyright_header,
+		debug,
+	):
 		settings = playground.settings
 		eprefix = settings["EPREFIX"]
 		eroot = settings["EROOT"]
@@ -284,39 +316,50 @@ class SimpleRepomanTestCase(TestCase):
 
 			for cwd in ("", "dev-libs", "dev-libs/A", "dev-libs/B"):
 				abs_cwd = os.path.join(test_repo_symlink, cwd)
-				proc = subprocess.Popen(repoman_cmd + ("full",),
-					cwd=abs_cwd, env=env, stdout=stdout)
+
+				proc = await asyncio.create_subprocess_exec(
+					*(repoman_cmd + ("full",)),
+					env=env,
+					stderr=None,
+					stdout=stdout,
+					cwd=abs_cwd
+				)
 
 				if debug:
-					proc.wait()
+					await proc.wait()
 				else:
-					output = proc.stdout.readlines()
-					proc.wait()
-					proc.stdout.close()
+					output, _err = await proc.communicate()
+					await proc.wait()
 					if proc.returncode != os.EX_OK:
-						for line in output:
-							sys.stderr.write(_unicode_decode(line))
+						portage.writemsg(output)
 
-				self.assertEqual(os.EX_OK, proc.returncode,
-					"repoman failed in %s" % (cwd,))
+				self.assertEqual(
+					os.EX_OK, proc.returncode, "repoman failed in %s" % (cwd,)
+				)
 
 			if git_binary is not None:
 				for cwd, cmd in git_test:
 					abs_cwd = os.path.join(test_repo_symlink, cwd)
-					proc = subprocess.Popen(cmd,
-						cwd=abs_cwd, env=env, stdout=stdout)
+					proc = await asyncio.create_subprocess_exec(
+						*cmd, env=env, stderr=None, stdout=stdout, cwd=abs_cwd
+					)
 
 					if debug:
-						proc.wait()
+						await proc.wait()
 					else:
-						output = proc.stdout.readlines()
-						proc.wait()
-						proc.stdout.close()
+						output, _err = await proc.communicate()
+						await proc.wait()
 						if proc.returncode != os.EX_OK:
-							for line in output:
-								sys.stderr.write(_unicode_decode(line))
-
-					self.assertEqual(os.EX_OK, proc.returncode,
-						"%s failed in %s" % (cmd, cwd,))
+							portage.writemsg(output)
+
+					self.assertEqual(
+						os.EX_OK,
+						proc.returncode,
+						"%s failed in %s"
+						% (
+							cmd,
+							cwd,
+						),
+					)
 		finally:
 			playground.cleanup()


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/tests/simple/
@ 2021-03-29  0:21 Zac Medico
  0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2021-03-29  0:21 UTC (permalink / raw
  To: gentoo-commits

commit:     ba58bc1ae12a59c5a5a7c2cd8ed747084c5b0fe1
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 28 15:43:54 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Mar 29 00:19:50 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=ba58bc1a

SimpleRepomanTestCase: collect results from subprocesses

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 repoman/lib/repoman/tests/simple/test_simple.py | 73 +++++++++++++++++++++++--
 1 file changed, 67 insertions(+), 6 deletions(-)

diff --git a/repoman/lib/repoman/tests/simple/test_simple.py b/repoman/lib/repoman/tests/simple/test_simple.py
index a4cdf5207..2439c936b 100644
--- a/repoman/lib/repoman/tests/simple/test_simple.py
+++ b/repoman/lib/repoman/tests/simple/test_simple.py
@@ -3,6 +3,7 @@
 
 import subprocess
 import time
+import types
 
 from repoman._portage import portage
 from portage import os
@@ -10,13 +11,63 @@ from portage.process import find_binary
 from portage.tests.resolver.ResolverPlayground import ResolverPlayground
 from portage.util import ensure_dirs
 from portage.util.futures import asyncio
+from portage.util.futures._asyncio.streams import _reader
+from portage.util._async.AsyncFunction import AsyncFunction
 
 # pylint: disable=ungrouped-imports
 from repoman import REPOMAN_BASE_PATH
 from repoman.copyrights import update_copyright_year
+from repoman.main import _repoman_init, _repoman_scan, _handle_result
 from repoman.tests import TestCase
 
 
+class RepomanRun(types.SimpleNamespace):
+	async def run(self):
+		self.expected = getattr(self, "expected", None) or {"returncode": 0}
+		if self.debug:
+			fd_pipes = {}
+			pr = None
+			pw = None
+		else:
+			pr, pw = os.pipe()
+			fd_pipes = {1: pw, 2: pw}
+			pr = open(pr, "rb", 0)
+
+		proc = AsyncFunction(
+			scheduler=asyncio.get_event_loop(),
+			target=self._subprocess,
+			args=(self.args, self.cwd, self.env, self.expected, self.debug),
+			fd_pipes=fd_pipes,
+		)
+
+		proc.start()
+		if pw is not None:
+			os.close(pw)
+
+		await proc.async_wait()
+
+		if pr is None:
+			stdio = None
+		else:
+			stdio = await _reader(pr)
+
+		self.result = {
+			"stdio": stdio,
+			"result": proc.result,
+		}
+
+	@staticmethod
+	def _subprocess(args, cwd, env, expected, debug):
+		os.chdir(cwd)
+		os.environ.update(env)
+		repoman_vars = _repoman_init(["repoman"] + args)
+		if repoman_vars.exitcode is not None:
+			return repoman_vars.exitcode
+		result = _repoman_scan(*repoman_vars)
+		returncode = _handle_result(*repoman_vars, result)
+		return {"returncode": returncode}
+
+
 class SimpleRepomanTestCase(TestCase):
 
 	def testCopyrightUpdate(self):
@@ -229,23 +280,23 @@ class SimpleRepomanTestCase(TestCase):
 		committer_email = "gentoo-dev@gentoo.org"
 
 		git_test = (
-			("", repoman_cmd + ("manifest",)),
+			("", RepomanRun(args=["manifest"])),
 			("", git_cmd + ("config", "--global", "user.name", committer_name,)),
 			("", git_cmd + ("config", "--global", "user.email", committer_email,)),
 			("", git_cmd + ("init-db",)),
 			("", git_cmd + ("add", ".")),
 			("", git_cmd + ("commit", "-a", "-m", "add whole repo")),
-			("", repoman_cmd + ("full", "-d")),
-			("", repoman_cmd + ("full", "--include-profiles", "default/linux/x86/test_profile")),
+			("", RepomanRun(args=["full", "-d"])),
+			("", RepomanRun(args=["full", "--include-profiles", "default/linux/x86/test_profile"])),
 			("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "2.ebuild")),
 			("", git_cmd + ("add", test_ebuild[:-8] + "2.ebuild")),
-			("", repoman_cmd + ("commit", "-m", "cat/pkg: bump to version 2")),
+			("", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 2"])),
 			("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "3.ebuild")),
 			("", git_cmd + ("add", test_ebuild[:-8] + "3.ebuild")),
-			("dev-libs", repoman_cmd + ("commit", "-m", "cat/pkg: bump to version 3")),
+			("dev-libs", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 3"])),
 			("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "4.ebuild")),
 			("", git_cmd + ("add", test_ebuild[:-8] + "4.ebuild")),
-			("dev-libs/A", repoman_cmd + ("commit", "-m", "cat/pkg: bump to version 4")),
+			("dev-libs/A", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 4"])),
 		)
 
 		env = {
@@ -340,6 +391,16 @@ class SimpleRepomanTestCase(TestCase):
 			if git_binary is not None:
 				for cwd, cmd in git_test:
 					abs_cwd = os.path.join(test_repo_symlink, cwd)
+					if isinstance(cmd, RepomanRun):
+						cmd.cwd = abs_cwd
+						cmd.env = env
+						cmd.debug = debug
+						await cmd.run()
+						if cmd.result["result"] != cmd.expected and cmd.result.get("stdio"):
+							portage.writemsg(cmd.result["stdio"])
+						self.assertEqual(cmd.result["result"], cmd.expected)
+						continue
+
 					proc = await asyncio.create_subprocess_exec(
 						*cmd, env=env, stderr=None, stdout=stdout, cwd=abs_cwd
 					)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/tests/simple/
@ 2021-03-29  4:44 Zac Medico
  0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2021-03-29  4:44 UTC (permalink / raw
  To: gentoo-commits

commit:     f84d0e45ca4cda2674d3f47f51729a6a8d0c7600
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 29 04:18:57 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Mar 29 04:26:23 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f84d0e45

SimpleRepomanTestCase: compare QATracker results to expected values

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 repoman/lib/repoman/tests/simple/test_simple.py | 29 +++++++++++++++++++------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/repoman/lib/repoman/tests/simple/test_simple.py b/repoman/lib/repoman/tests/simple/test_simple.py
index 2439c936b..e64ba4f07 100644
--- a/repoman/lib/repoman/tests/simple/test_simple.py
+++ b/repoman/lib/repoman/tests/simple/test_simple.py
@@ -1,6 +1,7 @@
 # Copyright 2011-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import collections
 import subprocess
 import time
 import types
@@ -65,7 +66,20 @@ class RepomanRun(types.SimpleNamespace):
 			return repoman_vars.exitcode
 		result = _repoman_scan(*repoman_vars)
 		returncode = _handle_result(*repoman_vars, result)
-		return {"returncode": returncode}
+		qawarnings = repoman_vars.vcs_settings.qatracker.qawarnings
+		warns = collections.defaultdict(list)
+		fails = collections.defaultdict(list)
+		for qacat, issues in repoman_vars.vcs_settings.qatracker.fails.items():
+			if qacat in qawarnings:
+				warns[qacat].extend(issues)
+			else:
+				fails[qacat].extend(issues)
+		result = {"returncode": returncode}
+		if fails:
+			result["fails"] = fails
+		if warns:
+			result["warns"] = warns
+		return result
 
 
 class SimpleRepomanTestCase(TestCase):
@@ -122,9 +136,9 @@ class SimpleRepomanTestCase(TestCase):
 			self.assertFalse(True, skip_reason)
 			return
 
-		copyright_header = """# Copyright 1999-%s Gentoo Foundation
+		copyright_header = """# Copyright 1999-%s Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
-# $Header: $
+
 """ % time.gmtime().tm_year
 
 		repo_configs = {
@@ -278,6 +292,7 @@ class SimpleRepomanTestCase(TestCase):
 
 		committer_name = "Gentoo Dev"
 		committer_email = "gentoo-dev@gentoo.org"
+		expected_warnings = {"returncode": 0}
 
 		git_test = (
 			("", RepomanRun(args=["manifest"])),
@@ -286,14 +301,14 @@ class SimpleRepomanTestCase(TestCase):
 			("", git_cmd + ("init-db",)),
 			("", git_cmd + ("add", ".")),
 			("", git_cmd + ("commit", "-a", "-m", "add whole repo")),
-			("", RepomanRun(args=["full", "-d"])),
-			("", RepomanRun(args=["full", "--include-profiles", "default/linux/x86/test_profile"])),
+			("", RepomanRun(args=["full", "-d"], expected=expected_warnings)),
+			("", RepomanRun(args=["full", "--include-profiles", "default/linux/x86/test_profile"], expected=expected_warnings)),
 			("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "2.ebuild")),
 			("", git_cmd + ("add", test_ebuild[:-8] + "2.ebuild")),
-			("", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 2"])),
+			("", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 2"], expected=expected_warnings)),
 			("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "3.ebuild")),
 			("", git_cmd + ("add", test_ebuild[:-8] + "3.ebuild")),
-			("dev-libs", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 3"])),
+			("dev-libs", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 3"], expected=expected_warnings)),
 			("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "4.ebuild")),
 			("", git_cmd + ("add", test_ebuild[:-8] + "4.ebuild")),
 			("dev-libs/A", RepomanRun(args=["commit", "-m", "cat/pkg: bump to version 4"])),


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/tests/simple/
@ 2021-03-31  7:46 Zac Medico
  0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2021-03-31  7:46 UTC (permalink / raw
  To: gentoo-commits

commit:     b09b4071151d8e3a81f3576843d00f88eb407799
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 31 07:45:23 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Mar 31 07:46:15 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=b09b4071

SimpleRepomanTestCase: use -vvvv for debug mode

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 repoman/lib/repoman/tests/simple/test_simple.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/repoman/lib/repoman/tests/simple/test_simple.py b/repoman/lib/repoman/tests/simple/test_simple.py
index 3a699a708..60c62acc1 100644
--- a/repoman/lib/repoman/tests/simple/test_simple.py
+++ b/repoman/lib/repoman/tests/simple/test_simple.py
@@ -62,6 +62,8 @@ class RepomanRun(types.SimpleNamespace):
 	def _subprocess(args, cwd, env, expected, debug):
 		os.chdir(cwd)
 		os.environ.update(env)
+		if debug:
+			args = ["-vvvv"] + args
 		repoman_vars = _repoman_init(["repoman"] + args)
 		if repoman_vars.exitcode is not None:
 			return repoman_vars.exitcode


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/tests/simple/
@ 2021-04-11 18:05 Zac Medico
  0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2021-04-11 18:05 UTC (permalink / raw
  To: gentoo-commits

commit:     2eb3ca092a528e0722e0ca32f616836ed8039936
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 11 17:47:21 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Apr 11 18:04:22 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=2eb3ca09

SimpleRepomanTestCase: update portage.const.EPREFIX after fork

Update portage.const.EPREFIX in each RepomanRun fork, since
the portage.const PORTAGE_OVERRIDE_EPREFIX logic only executes
when the module is first loaded in the parent process.

Fixes: ba58bc1ae12a ("SimpleRepomanTestCase: collect results from subprocesses")
Bug: https://bugs.gentoo.org/779508
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 repoman/lib/repoman/tests/simple/test_simple.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/repoman/lib/repoman/tests/simple/test_simple.py b/repoman/lib/repoman/tests/simple/test_simple.py
index c4a864ff8..9ec01df3b 100644
--- a/repoman/lib/repoman/tests/simple/test_simple.py
+++ b/repoman/lib/repoman/tests/simple/test_simple.py
@@ -62,6 +62,7 @@ class RepomanRun(types.SimpleNamespace):
 	def _subprocess(args, cwd, env, expected, debug):
 		os.chdir(cwd)
 		os.environ.update(env)
+		portage.const.EPREFIX = env["PORTAGE_OVERRIDE_EPREFIX"]
 		if debug:
 			args = ["-vvvv"] + args
 		repoman_vars = _repoman_init(["repoman"] + args)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-11 18:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-29  0:21 [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/tests/simple/ Zac Medico
  -- strict thread matches above, loose matches on Subject: below --
2021-04-11 18:05 Zac Medico
2021-03-31  7:46 Zac Medico
2021-03-29  4:44 Zac Medico
2021-03-28 19:53 Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox