From 8b9a0c521f9d122b33c9eac570fdda56506a984a Mon Sep 17 00:00:00 2001 From: Loren Schlomer Date: Thu, 24 Jan 2019 15:45:57 -0800 Subject: [PATCH] Added a unit test for keyboard interrupt --- cli/lesspass/core.py | 3 +++ cli/test-requirements.txt | 3 ++- cli/tests/test_interaction.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 cli/tests/test_interaction.py diff --git a/cli/lesspass/core.py b/cli/lesspass/core.py index 94b9e40..68290a4 100644 --- a/cli/lesspass/core.py +++ b/cli/lesspass/core.py @@ -52,3 +52,6 @@ def main(args=sys.argv[1:]): print("-" * 80) else: print(generated_password) + +if __name__ == '__main__': + main() diff --git a/cli/test-requirements.txt b/cli/test-requirements.txt index 6f7ca4c..2879f26 100644 --- a/cli/test-requirements.txt +++ b/cli/test-requirements.txt @@ -1,4 +1,5 @@ tox pytest flake8 -mock \ No newline at end of file +mock +pexpect diff --git a/cli/tests/test_interaction.py b/cli/tests/test_interaction.py new file mode 100644 index 0000000..69e1096 --- /dev/null +++ b/cli/tests/test_interaction.py @@ -0,0 +1,15 @@ +import unittest +import pexpect +import signal +import time + +class TestInteraction(unittest.TestCase): + def test_keyboard_interrupt(self): + + p = pexpect.spawn('/bin/bash -c "python lesspass/core.py --prompt"') + time.sleep(1) + + p.kill(signal.SIGINT) + p.expect(pexpect.EOF) + + self.assertEqual(p.before, b'Site: ')