Tests fail when git user is not set
Closed this issue · 1 comments
Some tests fail when run by a user that doesn’t have user.name
and user.email
defined.
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/test_dzonegit.py:27: AssertionError
---------------------------- Captured stdout setup -----------------------------
Initialized empty Git repository in /tmp/pytest-of-buildozer/pytest-82/.git/
----------------------------- Captured stderr call -----------------------------
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'buildozer@build-3-12-x86_64.(none)')
Full log from the builder
============================= test session starts ============================== platform linux -- Python 3.8.3, pytest-5.4.2, py-1.8.1, pluggy-0.13.1 rootdir: /home/buildozer/aports/community/dzonegit/src/dzonegit-0.13 collected 21 itemstest_dzonegit.py FF.....F...F....F.... [100%]
=================================== FAILURES ===================================
________________________________ test_get_head _________________________________
git_dir = local('/tmp/pytest-of-buildozer/pytest-82')
def test_get_head(git_dir):
git_dir.chdir()
assert dzonegit.get_head() == "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
git_dir.join("dummy").write("dummy\n")
subprocess.call(["git", "add", "dummy"])
subprocess.call(["git", "commit", "-m", "dummy"])
assert dzonegit.get_head() != "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
E AssertionError: assert '4b825dc642cb6eb9a060e54bf8d69288fbee4904' != '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
E + where '4b825dc642cb6eb9a060e54bf8d69288fbee4904' = <function get_head at 0x7f97ab0e1160>()
E + where <function get_head at 0x7f97ab0e1160> = dzonegit.get_head
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/test_dzonegit.py:27: AssertionError
---------------------------- Captured stdout setup -----------------------------
Initialized empty Git repository in /tmp/pytest-of-buildozer/pytest-82/.git/
----------------------------- Captured stderr call -----------------------------
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'buildozer@build-3-12-x86_64.(none)')
_________________________ test_check_whitespace_errors _________________________
git_dir = local('/tmp/pytest-of-buildozer/pytest-82')
def test_check_whitespace_errors(git_dir):
git_dir.chdir()
git_dir.join("whitespace").write(" ")
subprocess.call(["git", "add", "whitespace"])
with pytest.raises(ValueError):
dzonegit.check_whitespace_errors(dzonegit.get_head())
subprocess.call(["git", "commit", "-m", "whitespace"])
with pytest.raises(ValueError):
dzonegit.check_whitespace_errors("HEAD~", dzonegit.get_head())
subprocess.call(["git", "rm", "-f", "whitespace"])
subprocess.call(["git", "commit", "-m", "rm whitespace"])
dzonegit.check_whitespace_errors(dzonegit.get_head())
dzonegit.check_whitespace_errors("HEAD~", dzonegit.get_head())
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/test_dzonegit.py:42:
against = 'HEAD~', revision = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
def check_whitespace_errors(against, revision=None):
if revision:
cmd = ["git", "diff-tree", "--check", against, revision]
else:
cmd = ["git", "diff-index", "--check", "--cached", against]
r = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if r.returncode != 0:
raise HookException(
"Whitespace errors",
stderr=r.stdout.decode("utf-8"),
)
E dzonegit.HookException: Whitespace errors
E
E fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree.
E Use '--' to separate paths from revisions, like this:
E 'git [...] -- [...]'
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/dzonegit.py:68: HookException
----------------------------- Captured stdout call -----------------------------
rm 'whitespace'
----------------------------- Captured stderr call -----------------------------
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'buildozer@build-3-12-x86_64.(none)')
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'buildozer@build-3-12-x86_64.(none)')
____________________________ test_get_altered_files ____________________________
git_dir = local('/tmp/pytest-of-buildozer/pytest-82')
def test_get_altered_files(git_dir):
git_dir.chdir()
git_dir.join("dummy").write("dummy2\n")
git_dir.join("new").write("newfile\n")
subprocess.call(["git", "add", "dummy", "new"])
files = set(dzonegit.get_altered_files("HEAD", "AM"))
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/test_dzonegit.py:121:
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/dzonegit.py:179: in get_altered_files
r = subprocess.run(
input = None, capture_output = False, timeout = None, check = True
popenargs = (['git', 'diff', '--name-only', '-z', '--no-renames', '--diff-filter=AM', ...],)
kwargs = {'stderr': -3, 'stdout': -1}
process = <subprocess.Popen object at 0x7f97ab17b8b0>, stdout = b''
stderr = None, retcode = 128
def run(*popenargs,
input=None, capture_output=False, timeout=None, check=False, **kwargs):
"""Run command with arguments and return a CompletedProcess instance.
The returned instance will have attributes args, returncode, stdout and
stderr. By default, stdout and stderr are not captured, and those attributes
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
If check is True and the exit code was non-zero, it raises a
CalledProcessError. The CalledProcessError object will have the return code
in the returncode attribute, and output & stderr attributes if those streams
were captured.
If timeout is given, and the process takes too long, a TimeoutExpired
exception will be raised.
There is an optional argument "input", allowing you to
pass bytes or a string to the subprocess's stdin. If you use this argument
you may not also use the Popen constructor's "stdin" argument, as
it will be used internally.
By default, all communication is in bytes, and therefore any "input" should
be bytes, and the stdout and stderr will be bytes. If in text mode, any
"input" should be a string, and stdout and stderr will be strings decoded
according to locale encoding, or by "encoding" if set. Text mode is
triggered by setting any of text, encoding, errors or universal_newlines.
The other arguments are the same as for the Popen constructor.
"""
if input is not None:
if kwargs.get('stdin') is not None:
raise ValueError('stdin and input arguments may not both be used.')
kwargs['stdin'] = PIPE
if capture_output:
if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
raise ValueError('stdout and stderr arguments may not be used '
'with capture_output.')
kwargs['stdout'] = PIPE
kwargs['stderr'] = PIPE
with Popen(*popenargs, **kwargs) as process:
try:
stdout, stderr = process.communicate(input, timeout=timeout)
except TimeoutExpired as exc:
process.kill()
if _mswindows:
# Windows accumulates the output in a single blocking
# read() call run on child threads, with the timeout
# being done in a join() on those threads. communicate()
# _after_ kill() is required to collect that and add it
# to the exception.
exc.stdout, exc.stderr = process.communicate()
else:
# POSIX _communicate already populated the output so
# far into the TimeoutExpired exception.
process.wait()
raise
except: # Including KeyboardInterrupt, communicate handled that.
process.kill()
# We don't call process.wait() as .__exit__ does that for us.
raise
retcode = process.poll()
if check and retcode:
raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
E subprocess.CalledProcessError: Command '['git', 'diff', '--name-only', '-z', '--no-renames', '--diff-filter=AM', '--cached', 'HEAD']' returned non-zero exit status 128.
/usr/lib/python3.8/subprocess.py:512: CalledProcessError
___________________________ test_check_updated_zones ___________________________
git_dir = local('/tmp/pytest-of-buildozer/pytest-82')
def test_check_updated_zones(git_dir):
git_dir.chdir()
git_dir.join("dummy.zone").write("")
subprocess.call(["git", "add", "dummy.zone"])
with pytest.raises(ValueError):
dzonegit.check_updated_zones(dzonegit.get_head())
subprocess.call(["git", "commit", "-m", "empty dummy.zone"])
with pytest.raises(ValueError):
dzonegit.check_updated_zones("HEAD~", "HEAD")
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/test_dzonegit.py:226:
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/dzonegit.py:234: in check_updated_zones
for f in get_altered_files(against, "AMCR", revision):
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/dzonegit.py:179: in get_altered_files
r = subprocess.run(
input = None, capture_output = False, timeout = None, check = True
popenargs = (['git', 'diff', '--name-only', '-z', '--no-renames', '--diff-filter=AMCR', ...],)
kwargs = {'stderr': -3, 'stdout': -1}
process = <subprocess.Popen object at 0x7f97ab1316a0>, stdout = b''
stderr = None, retcode = 128
def run(*popenargs,
input=None, capture_output=False, timeout=None, check=False, **kwargs):
"""Run command with arguments and return a CompletedProcess instance.
The returned instance will have attributes args, returncode, stdout and
stderr. By default, stdout and stderr are not captured, and those attributes
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
If check is True and the exit code was non-zero, it raises a
CalledProcessError. The CalledProcessError object will have the return code
in the returncode attribute, and output & stderr attributes if those streams
were captured.
If timeout is given, and the process takes too long, a TimeoutExpired
exception will be raised.
There is an optional argument "input", allowing you to
pass bytes or a string to the subprocess's stdin. If you use this argument
you may not also use the Popen constructor's "stdin" argument, as
it will be used internally.
By default, all communication is in bytes, and therefore any "input" should
be bytes, and the stdout and stderr will be bytes. If in text mode, any
"input" should be a string, and stdout and stderr will be strings decoded
according to locale encoding, or by "encoding" if set. Text mode is
triggered by setting any of text, encoding, errors or universal_newlines.
The other arguments are the same as for the Popen constructor.
"""
if input is not None:
if kwargs.get('stdin') is not None:
raise ValueError('stdin and input arguments may not both be used.')
kwargs['stdin'] = PIPE
if capture_output:
if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
raise ValueError('stdout and stderr arguments may not be used '
'with capture_output.')
kwargs['stdout'] = PIPE
kwargs['stderr'] = PIPE
with Popen(*popenargs, **kwargs) as process:
try:
stdout, stderr = process.communicate(input, timeout=timeout)
except TimeoutExpired as exc:
process.kill()
if _mswindows:
# Windows accumulates the output in a single blocking
# read() call run on child threads, with the timeout
# being done in a join() on those threads. communicate()
# _after_ kill() is required to collect that and add it
# to the exception.
exc.stdout, exc.stderr = process.communicate()
else:
# POSIX _communicate already populated the output so
# far into the TimeoutExpired exception.
process.wait()
raise
except: # Including KeyboardInterrupt, communicate handled that.
process.kill()
# We don't call process.wait() as .__exit__ does that for us.
raise
retcode = process.poll()
if check and retcode:
raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
E subprocess.CalledProcessError: Command '['git', 'diff', '--name-only', '-z', '--no-renames', '--diff-filter=AMCR', 'HEAD~', 'HEAD']' returned non-zero exit status 128.
/usr/lib/python3.8/subprocess.py:512: CalledProcessError
----------------------------- Captured stdout call -----------------------------
Checking file dummy.zone
----------------------------- Captured stderr call -----------------------------
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'buildozer@build-3-12-x86_64.(none)')
______________________________ test_post_receive _______________________________
git_dir = local('/tmp/pytest-of-buildozer/pytest-82')
def test_post_receive(git_dir):
git_dir.chdir()
head = dzonegit.get_head()
revisions = "{} {} refs/heads/master\n".format(
"0000000000000000000000000000000000000000",
head,
)
stdin = StringIO(revisions)
codir = git_dir.join("co")
subprocess.call(["git", "config", "dzonegit.checkoutpath", str(codir)])
subprocess.call([
"git", "config", "dzonegit.reconfigcmd",
"echo TEST >{}/test".format(codir),
])
dzonegit.post_receive(stdin)
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/test_dzonegit.py:346:
/home/buildozer/aports/community/dzonegit/src/dzonegit-0.13/dzonegit.py:492: in post_receive
subprocess.run(
input = None, capture_output = False, timeout = None, check = True
popenargs = (['git', 'checkout', '-f', 'master'],)
kwargs = {'env': {'ABUILD_LAST_COMMIT': 'ae9f53b631f0eb9b130929ab1726089809cbdef0', 'APORTSDIR': '/home/buildozer/aports', 'CARGO_HOME': '/var/cache/distfiles/v3.12/cargo', 'CC': 'gcc', ...}, 'stderr': -3}
process = <subprocess.Popen object at 0x7f97aaeab790>, stdout = None
stderr = None, retcode = 1
def run(*popenargs,
input=None, capture_output=False, timeout=None, check=False, **kwargs):
"""Run command with arguments and return a CompletedProcess instance.
The returned instance will have attributes args, returncode, stdout and
stderr. By default, stdout and stderr are not captured, and those attributes
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
If check is True and the exit code was non-zero, it raises a
CalledProcessError. The CalledProcessError object will have the return code
in the returncode attribute, and output & stderr attributes if those streams
were captured.
If timeout is given, and the process takes too long, a TimeoutExpired
exception will be raised.
There is an optional argument "input", allowing you to
pass bytes or a string to the subprocess's stdin. If you use this argument
you may not also use the Popen constructor's "stdin" argument, as
it will be used internally.
By default, all communication is in bytes, and therefore any "input" should
be bytes, and the stdout and stderr will be bytes. If in text mode, any
"input" should be a string, and stdout and stderr will be strings decoded
according to locale encoding, or by "encoding" if set. Text mode is
triggered by setting any of text, encoding, errors or universal_newlines.
The other arguments are the same as for the Popen constructor.
"""
if input is not None:
if kwargs.get('stdin') is not None:
raise ValueError('stdin and input arguments may not both be used.')
kwargs['stdin'] = PIPE
if capture_output:
if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
raise ValueError('stdout and stderr arguments may not be used '
'with capture_output.')
kwargs['stdout'] = PIPE
kwargs['stderr'] = PIPE
with Popen(*popenargs, **kwargs) as process:
try:
stdout, stderr = process.communicate(input, timeout=timeout)
except TimeoutExpired as exc:
process.kill()
if _mswindows:
# Windows accumulates the output in a single blocking
# read() call run on child threads, with the timeout
# being done in a join() on those threads. communicate()
# _after_ kill() is required to collect that and add it
# to the exception.
exc.stdout, exc.stderr = process.communicate()
else:
# POSIX _communicate already populated the output so
# far into the TimeoutExpired exception.
process.wait()
raise
except: # Including KeyboardInterrupt, communicate handled that.
process.kill()
# We don't call process.wait() as .__exit__ does that for us.
raise
retcode = process.poll()
if check and retcode:
raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
E subprocess.CalledProcessError: Command '['git', 'checkout', '-f', 'master']' returned non-zero exit status 1.
/usr/lib/python3.8/subprocess.py:512: CalledProcessError
----------------------------- Captured stdout call -----------------------------
Checking out repository into /tmp/pytest-of-buildozer/pytest-82/co�
=========================== short test summary info ============================
FAILED test_dzonegit.py::test_get_head - AssertionError: assert '4b825dc642cb...
FAILED test_dzonegit.py::test_check_whitespace_errors - dzonegit.HookExceptio...
FAILED test_dzonegit.py::test_get_altered_files - subprocess.CalledProcessErr...
FAILED test_dzonegit.py::test_check_updated_zones - subprocess.CalledProcessE...
FAILED test_dzonegit.py::test_post_receive - subprocess.CalledProcessError: C...
========================= 5 failed, 16 passed in 1.17s =========================
ERROR: dzonegit: check failed
IMO the tests shouldn’t assume that the user.name
and user.email
are set globally.