From b6215914784096189db0ef4fd9d580a249a19675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 3 May 2020 23:38:25 +0300 Subject: [PATCH] test: port most umount test cases to pytest+pexpect --- test/lib/completions/umount.exp | 66 +------------------------------- test/t/test_umount.py | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 65 deletions(-) diff --git a/test/lib/completions/umount.exp b/test/lib/completions/umount.exp index 03144355c74..bc7b74318b8 100644 --- a/test/lib/completions/umount.exp +++ b/test/lib/completions/umount.exp @@ -1,36 +1,10 @@ -# umount completion from fstab can't be tested directly because it -# (correctly) uses absolute paths. So we create a custom completion which -# reads from a file in our text fixture instead. -proc setup_dummy_mnt {} { - assert_bash_exec {unset COMPREPLY cur} - assert_bash_exec {unset -f _mnt} - - assert_bash_exec { \ - _mnt() { \ - local cur=$(_get_cword); \ - _linux_fstab $(_get_pword) < "$SRCDIRABS/fixtures/mount/test-fstab"; \ - }; \ - complete -F _mnt mnt \ - } -} - - -proc teardown_dummy_mnt {} { - assert_bash_exec {unset COMPREPLY cur} - assert_bash_exec {unset -f _mnt} - assert_bash_exec {complete -r mnt} -} - - proc setup {} { save_env - setup_dummy_mnt } proc teardown {} { - teardown_dummy_mnt - assert_env_unmodified {/OLDPWD/d} + assert_env_unmodified } @@ -54,42 +28,4 @@ assert_bash_exec {unset var} sync_after_int -# Begin testing through mnt (see setup_dummy_mnt). -assert_complete {/mnt/nice-test-path} {mnt /mnt/nice-test-p} -sync_after_int - -assert_complete {/mnt/nice\ test-path} {mnt /mnt/nice\ test-p} -sync_after_int - -assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$test-p} -sync_after_int - -assert_complete {/mnt/nice\ test\\path} {mnt /mnt/nice\ test\\p} -sync_after_int - -assert_complete {{/mnt/nice\ test\\path} {/mnt/nice\ test-path}} \ - {mnt /mnt/nice\ } "" -expect-cmd-minus {/mnt/nice\ } -sync_after_int - -assert_complete {/mnt/nice\$test-path} {mnt /mnt/nice\$} -sync_after_int - -assert_complete {/mnt/nice\'test-path} {mnt /mnt/nice\'} -sync_after_int - -assert_complete {/mnt/other\'test\ path} {mnt /mnt/other} -sync_after_int - -assert_complete {Ubuntu\ Karmic} {mnt -L Ubu} -sync_after_int - -assert_complete {Debian-it\'s\ awesome} {mnt -L Deb} -sync_after_int - -# This does not work. Proper support for this requires smarter parsing of -# $COMP_LINE and it's not worth doing just for umount. -#assert_complete {$'/mnt/nice\ntest-path'} {mnt $'/mnt/nice\n} -#sync_after_int - - teardown diff --git a/test/t/test_umount.py b/test/t/test_umount.py index dd4ae0b5d45..dd3396af6c9 100644 --- a/test/t/test_umount.py +++ b/test/t/test_umount.py @@ -1,7 +1,74 @@ import pytest +from conftest import assert_bash_exec + class TestUmount: + @pytest.fixture(scope="class") + def dummy_mnt(self, request, bash): + """ + umount completion from fstab can't be tested directly because it + (correctly) uses absolute paths. So we create a custom completion which + reads from a file in our text fixture instead. + """ + assert_bash_exec(bash, "unset COMPREPLY cur; unset -f _mnt") + assert_bash_exec( + bash, + "_mnt() { " + "local cur=$(_get_cword); " + "_linux_fstab $(_get_pword) < mount/test-fstab; " + "} && complete -F _mnt mnt", + ) + request.addfinalizer( + lambda: assert_bash_exec(bash, "complete -r mnt; unset -f _mnt") + ) + @pytest.mark.complete("umount ") def test_1(self, completion): assert completion + + @pytest.mark.complete("mnt /mnt/nice-test-p") + def test_mnt_basic(self, completion, dummy_mnt): + assert completion == "/mnt/nice-test-path" + + # Note in tests below that return only one result, that the result + # is shell unescaped due to how assert_complete handles the + # "one result on same line case". + + @pytest.mark.complete(r"mnt /mnt/nice\ test-p") + def test_mnt_space(self, completion, dummy_mnt): + assert completion == r"/mnt/nice test-path" + + @pytest.mark.complete(r"mnt /mnt/nice\$test-p") + def test_mnt_dollar(self, completion, dummy_mnt): + assert completion == "/mnt/nice$test-path" + + @pytest.mark.complete(r"mnt /mnt/nice\ test\\p") + def test_mnt_backslash(self, completion, dummy_mnt): + assert completion == r"/mnt/nice test\path" + + @pytest.mark.complete(r"mnt /mnt/nice\ ") + def test_mnt_after_space(self, completion, dummy_mnt): + assert completion == sorted( + (r"/mnt/nice\ test\\path", r"/mnt/nice\ test-path") + ) + + @pytest.mark.complete(r"mnt /mnt/nice\$") + def test_mnt_at_dollar(self, completion, dummy_mnt): + assert completion == "/mnt/nice$test-path" + + @pytest.mark.complete(r"mnt /mnt/nice\'") + def test_mnt_at_quote(self, completion, dummy_mnt): + assert completion == "/mnt/nice'test-path" + + @pytest.mark.complete("mnt /mnt/other") + def test_mnt_other(self, completion, dummy_mnt): + assert completion == "/mnt/other'test path" + + @pytest.mark.complete("mnt -L Ubu") + def test_mnt_label_space(self, completion, dummy_mnt): + assert completion == "Ubuntu Karmic" + + @pytest.mark.complete("mnt -L Deb") + def test_mnt_label_quote(self, completion, dummy_mnt): + assert completion == "Debian-it's awesome"