Skip to content

Instantly share code, notes, and snippets.

@KamilaBorowska
Created December 28, 2020 23:40
Show Gist options
  • Save KamilaBorowska/4239c96f6a4e81e4d97b3340e092ed57 to your computer and use it in GitHub Desktop.
Save KamilaBorowska/4239c96f6a4e81e4d97b3340e092ed57 to your computer and use it in GitHub Desktop.
_______________________________ TestChsh.test_2 ________________________________
self = <test_chsh.TestChsh object at 0x7ffff50daa90>
completion = <CompletionResult []>
@pytest.mark.complete("chsh -s ")
def test_2(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_chsh.py:11: AssertionError
_____________________________ TestEtherWake.test_1 _____________________________
self = <test_ether_wake.TestEtherWake object at 0x7ffff4ec0220>
completion = <CompletionResult []>
@pytest.mark.xfail(
os.environ.get("NETWORK") == "none",
reason="MAC addresses may be N/A with no networking configured",
)
@pytest.mark.complete("ether-wake ")
def test_1(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_ether_wake.py:14: AssertionError
______________________________ TestIfdown.test_1 _______________________________
self = <test_ifdown.TestIfdown object at 0x7ffff4d51970>
completion = <CompletionResult []>
@pytest.mark.xfail(in_container(), reason="Probably fails in a container")
@pytest.mark.complete("ifdown ")
def test_1(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_ifdown.py:10: AssertionError
______________________________ TestIfstat.test_2 _______________________________
self = <test_ifstat.TestIfstat object at 0x7ffff4d61d60>
completion = <CompletionResult []>
@pytest.mark.complete(
"ifstat -i ", xfail="ifstat -v | command grep -qF iproute2"
)
def test_2(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_ifstat.py:13: AssertionError
_______________________________ TestIfup.test_1 ________________________________
self = <test_ifup.TestIfup object at 0x7ffff4cfd190>
completion = <CompletionResult []>
@pytest.mark.xfail(in_container(), reason="Probably fails in a container")
@pytest.mark.complete("ifup ")
def test_1(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_ifup.py:10: AssertionError
_______________________________ TestIperf.test_2 _______________________________
self = <test_iperf.TestIperf object at 0x7ffff4c81a30>
completion = <CompletionResult []>
@pytest.mark.complete("iperf --bind ")
def test_2(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_iperf.py:11: AssertionError
______________________________ TestIperf3.test_2 _______________________________
self = <test_iperf3.TestIperf3 object at 0x7ffff4c99fa0>
completion = <CompletionResult []>
@pytest.mark.complete("iperf3 --bind ")
def test_2(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_iperf3.py:11: AssertionError
________________________________ TestLs.test_3 _________________________________
self = <test_ls.TestLs object at 0x7ffff4b74a90>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4b74850>
def test_3(self, bash):
"""~part should complete to ~full<SPACE> if home dir does not exist."""
res = (
> assert_bash_exec(
bash,
"for u in $(compgen -u); do "
"eval test -d ~$u || echo $u; unset u; done",
want_output=True,
)
.strip()
.split()
)
/build/source/test/t/test_ls.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4b74850>
cmd = 'for u in $(compgen -u); do eval test -d ~$u || echo $u; unset u; done'
want_output = True, want_newline = True
def assert_bash_exec(
bash: pexpect.spawn,
cmd: str,
want_output: Optional[bool] = False,
want_newline=True,
) -> str:
"""
:param want_output: if None, don't care if got output or not
"""
# Send command
bash.sendline(cmd)
bash.expect_exact(cmd)
# Find prompt, output is before it
bash.expect_exact("%s%s" % ("\r\n" if want_newline else "", PS1))
output = bash.before
# Retrieve exit status
echo = "echo $?"
bash.sendline(echo)
got = bash.expect(
[
r"^%s\r\n(\d+)\r\n%s" % (re.escape(echo), re.escape(PS1)),
PS1,
pexpect.EOF,
pexpect.TIMEOUT,
]
)
status = bash.match.group(1) if got == 0 else "unknown"
assert status == "0", 'Error running "%s": exit status=%s, output="%s"' % (
cmd,
status,
output,
)
if want_output is not None:
if output:
assert want_output, (
'Unexpected output from "%s": exit status=%s, output="%s"'
% (cmd, status, output)
)
else:
> assert not want_output, (
'Expected output from "%s": exit status=%s, output="%s"'
% (cmd, status, output)
)
E AssertionError: Expected output from "for u in $(compgen -u); do eval test -d ~$u || echo $u; unset u; done": exit status=0, output=""
E assert not True
/build/source/test/t/conftest.py:347: AssertionError
______________________________ TestNethogs.test_1 ______________________________
self = <test_nethogs.TestNethogs object at 0x7ffff487daf0>
completion = <CompletionResult []>
@pytest.mark.complete("nethogs ")
def test_1(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_nethogs.py:7: AssertionError
______________________________ TestScreen.test_4 _______________________________
self = <test_screen.TestScreen object at 0x7ffff4571790>
completion = <CompletionResult []>
@pytest.mark.complete("screen -T vt")
def test_4(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_screen.py:20: AssertionError
______________________________ TestService.test_1 ______________________________
self = <test_service.TestService object at 0x7ffff44fd3a0>
completion = <CompletionResult []>
@pytest.mark.complete("service ")
def test_1(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_service.py:7: AssertionError
_______________________________ TestTime.test_1 ________________________________
self = <test_time.TestTime object at 0x7ffff4371dc0>
completion = <CompletionResult []>
@pytest.mark.complete("time set")
def test_1(self, completion):
> assert completion
E assert <CompletionResult []>
/build/source/test/t/test_time.py:9: AssertionError
___________________ TestUnitExpand.test_user_home_compreply ____________________
self = <test_unit_expand.TestUnitExpand object at 0x7ffff4042580>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff403dc40>
user_home = ('nixbld', '/homeless-shelter')
def test_user_home_compreply(self, bash, user_home):
user, home = user_home
output = assert_bash_exec(
bash,
r'cur="~%s"; _expand; printf "%%s\n" "$COMPREPLY"' % user,
want_output=True,
)
> assert output.strip() == home
E AssertionError: assert '/build' == '/homeless-shelter'
E - /homeless-shelter
E + /build
/build/source/test/t/unit/test_unit_expand.py:22: AssertionError
______________________ TestUnitExpand.test_user_home_cur _______________________
self = <test_unit_expand.TestUnitExpand object at 0x7ffff4042bb0>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff403dc40>
user_home = ('nixbld', '/homeless-shelter')
def test_user_home_cur(self, bash, user_home):
user, home = user_home
output = assert_bash_exec(
bash,
r'cur="~%s/a"; _expand; printf "%%s\n" "$cur"' % user,
want_output=True,
)
> assert output.strip() == "%s/a" % home
E AssertionError: assert '/build/a' == '/homeless-shelter/a'
E - /homeless-shelter/a
E + /build/a
/build/source/test/t/unit/test_unit_expand.py:31: AssertionError
_________ TestUnitExpandTildeByRef.test_expand[suffix_expanded0-False] _________
self = <test_unit_expand_tilde_by_ref.TestUnitExpandTildeByRef object at 0x7ffff4053940>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4053d00>
user_home = ('nixbld', '/homeless-shelter'), plain_tilde = False
suffix_expanded = ('', True)
@pytest.mark.parametrize("plain_tilde", (True, False))
@pytest.mark.parametrize(
"suffix_expanded",
(
("", True),
("/foo", True),
(r"/\$HOME", True),
("/a b", True),
("/*", True),
(";echo hello", False),
("/a;echo hello", True),
),
)
def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
user, home = user_home
suffix, expanded = suffix_expanded
if plain_tilde:
user = ""
if not suffix or not expanded:
home = "~"
elif not expanded:
home = "~%s" % user
output = assert_bash_exec(
bash,
r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
% (user, suffix),
want_output=True,
)
> assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)
E AssertionError: assert '/build' == '/homeless-shelter'
E - /homeless-shelter
E + /build
/build/source/test/t/unit/test_unit_expand_tilde_by_ref.py:46: AssertionError
_________ TestUnitExpandTildeByRef.test_expand[suffix_expanded1-False] _________
self = <test_unit_expand_tilde_by_ref.TestUnitExpandTildeByRef object at 0x7ffff4053550>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4053d00>
user_home = ('nixbld', '/homeless-shelter'), plain_tilde = False
suffix_expanded = ('/foo', True)
@pytest.mark.parametrize("plain_tilde", (True, False))
@pytest.mark.parametrize(
"suffix_expanded",
(
("", True),
("/foo", True),
(r"/\$HOME", True),
("/a b", True),
("/*", True),
(";echo hello", False),
("/a;echo hello", True),
),
)
def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
user, home = user_home
suffix, expanded = suffix_expanded
if plain_tilde:
user = ""
if not suffix or not expanded:
home = "~"
elif not expanded:
home = "~%s" % user
output = assert_bash_exec(
bash,
r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
% (user, suffix),
want_output=True,
)
> assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)
E AssertionError: assert '/build/foo' == '/homeless-shelter/foo'
E - /homeless-shelter/foo
E + /build/foo
/build/source/test/t/unit/test_unit_expand_tilde_by_ref.py:46: AssertionError
_________ TestUnitExpandTildeByRef.test_expand[suffix_expanded2-False] _________
self = <test_unit_expand_tilde_by_ref.TestUnitExpandTildeByRef object at 0x7ffff4042220>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4053d00>
user_home = ('nixbld', '/homeless-shelter'), plain_tilde = False
suffix_expanded = ('/\\$HOME', True)
@pytest.mark.parametrize("plain_tilde", (True, False))
@pytest.mark.parametrize(
"suffix_expanded",
(
("", True),
("/foo", True),
(r"/\$HOME", True),
("/a b", True),
("/*", True),
(";echo hello", False),
("/a;echo hello", True),
),
)
def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
user, home = user_home
suffix, expanded = suffix_expanded
if plain_tilde:
user = ""
if not suffix or not expanded:
home = "~"
elif not expanded:
home = "~%s" % user
output = assert_bash_exec(
bash,
r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
% (user, suffix),
want_output=True,
)
> assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)
E AssertionError: assert '/build/$HOME' == '/homeless-shelter/$HOME'
E - /homeless-shelter/$HOME
E + /build/$HOME
/build/source/test/t/unit/test_unit_expand_tilde_by_ref.py:46: AssertionError
_________ TestUnitExpandTildeByRef.test_expand[suffix_expanded3-False] _________
self = <test_unit_expand_tilde_by_ref.TestUnitExpandTildeByRef object at 0x7ffff4059820>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4053d00>
user_home = ('nixbld', '/homeless-shelter'), plain_tilde = False
suffix_expanded = ('/a b', True)
@pytest.mark.parametrize("plain_tilde", (True, False))
@pytest.mark.parametrize(
"suffix_expanded",
(
("", True),
("/foo", True),
(r"/\$HOME", True),
("/a b", True),
("/*", True),
(";echo hello", False),
("/a;echo hello", True),
),
)
def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
user, home = user_home
suffix, expanded = suffix_expanded
if plain_tilde:
user = ""
if not suffix or not expanded:
home = "~"
elif not expanded:
home = "~%s" % user
output = assert_bash_exec(
bash,
r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
% (user, suffix),
want_output=True,
)
> assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)
E AssertionError: assert '/build/a b' == '/homeless-shelter/a b'
E - /homeless-shelter/a b
E + /build/a b
/build/source/test/t/unit/test_unit_expand_tilde_by_ref.py:46: AssertionError
_________ TestUnitExpandTildeByRef.test_expand[suffix_expanded4-False] _________
self = <test_unit_expand_tilde_by_ref.TestUnitExpandTildeByRef object at 0x7ffff4067190>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4053d00>
user_home = ('nixbld', '/homeless-shelter'), plain_tilde = False
suffix_expanded = ('/*', True)
@pytest.mark.parametrize("plain_tilde", (True, False))
@pytest.mark.parametrize(
"suffix_expanded",
(
("", True),
("/foo", True),
(r"/\$HOME", True),
("/a b", True),
("/*", True),
(";echo hello", False),
("/a;echo hello", True),
),
)
def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
user, home = user_home
suffix, expanded = suffix_expanded
if plain_tilde:
user = ""
if not suffix or not expanded:
home = "~"
elif not expanded:
home = "~%s" % user
output = assert_bash_exec(
bash,
r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
% (user, suffix),
want_output=True,
)
> assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)
E AssertionError: assert '/build/*' == '/homeless-shelter/*'
E - /homeless-shelter/*
E + /build/*
/build/source/test/t/unit/test_unit_expand_tilde_by_ref.py:46: AssertionError
_________ TestUnitExpandTildeByRef.test_expand[suffix_expanded6-False] _________
self = <test_unit_expand_tilde_by_ref.TestUnitExpandTildeByRef object at 0x7ffff4067970>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4053d00>
user_home = ('nixbld', '/homeless-shelter'), plain_tilde = False
suffix_expanded = ('/a;echo hello', True)
@pytest.mark.parametrize("plain_tilde", (True, False))
@pytest.mark.parametrize(
"suffix_expanded",
(
("", True),
("/foo", True),
(r"/\$HOME", True),
("/a b", True),
("/*", True),
(";echo hello", False),
("/a;echo hello", True),
),
)
def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
user, home = user_home
suffix, expanded = suffix_expanded
if plain_tilde:
user = ""
if not suffix or not expanded:
home = "~"
elif not expanded:
home = "~%s" % user
output = assert_bash_exec(
bash,
r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
% (user, suffix),
want_output=True,
)
> assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)
E AssertionError: assert '/build/a;echo hello' == '/homeless-sh.../a;echo hello'
E - /homeless-shelter/a;echo hello
E + /build/a;echo hello
/build/source/test/t/unit/test_unit_expand_tilde_by_ref.py:46: AssertionError
__________________________ TestUnitIpAddresses.test_1 __________________________
self = <test_unit_ip_addresses.TestUnitIpAddresses object at 0x7ffff3ffc3d0>
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4025820>
def test_1(self, bash):
> assert_bash_exec(bash, "_ip_addresses")
/build/source/test/t/unit/test_unit_ip_addresses.py:30:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bash = <pexpect.pty_spawn.spawn object at 0x7ffff4025820>, cmd = '_ip_addresses'
want_output = False, want_newline = True
def assert_bash_exec(
bash: pexpect.spawn,
cmd: str,
want_output: Optional[bool] = False,
want_newline=True,
) -> str:
"""
:param want_output: if None, don't care if got output or not
"""
# Send command
bash.sendline(cmd)
bash.expect_exact(cmd)
# Find prompt, output is before it
bash.expect_exact("%s%s" % ("\r\n" if want_newline else "", PS1))
output = bash.before
# Retrieve exit status
echo = "echo $?"
bash.sendline(echo)
got = bash.expect(
[
r"^%s\r\n(\d+)\r\n%s" % (re.escape(echo), re.escape(PS1)),
PS1,
pexpect.EOF,
pexpect.TIMEOUT,
]
)
status = bash.match.group(1) if got == 0 else "unknown"
> assert status == "0", 'Error running "%s": exit status=%s, output="%s"' % (
cmd,
status,
output,
)
E AssertionError: Error running "_ip_addresses": exit status=1, output=""
E assert '1' == '0'
E - 0
E + 1
/build/source/test/t/conftest.py:335: AssertionError
__________________________ TestUnitIpAddresses.test_2 __________________________
self = <test_unit_ip_addresses.TestUnitIpAddresses object at 0x7ffff3fbb640>
functions = None, completion = <CompletionResult []>
@pytest.mark.complete("iaa ")
def test_2(self, functions, completion):
"""_ip_addresses -a should complete ip addresses."""
> assert completion
E assert <CompletionResult []>
/build/source/test/t/unit/test_unit_ip_addresses.py:35: AssertionError
__________________________ TestUnitIpAddresses.test_3 __________________________
self = <test_unit_ip_addresses.TestUnitIpAddresses object at 0x7ffff55a33d0>
functions = None, completion = <CompletionResult []>
@pytest.mark.complete("ia ")
def test_3(self, functions, completion):
"""_ip_addresses should complete ipv4 addresses."""
> assert completion
E assert <CompletionResult []>
/build/source/test/t/unit/test_unit_ip_addresses.py:41: AssertionError
__________________________ TestUnitIpAddresses.test_4 __________________________
self = <test_unit_ip_addresses.TestUnitIpAddresses object at 0x7ffff3f85dc0>
functions = None, completion = <CompletionResult []>
@pytest.mark.xfail(in_container(), reason="Probably fails in a container")
@pytest.mark.complete("ia6 ")
def test_4(self, functions, completion):
"""_ip_addresses -6 should complete ipv6 addresses."""
> assert completion
E assert <CompletionResult []>
/build/source/test/t/unit/test_unit_ip_addresses.py:48: AssertionError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment