From b614ed52a4aaf7678938448ef67f645a15ff2592 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Tue, 2 Aug 2022 09:15:20 +0200 Subject: Add an example of testing a command with the ExternamEditorMixin --- tests/test_mixins.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/test_mixins.py') diff --git a/tests/test_mixins.py b/tests/test_mixins.py index 1e2f91d..44ae165 100644 --- a/tests/test_mixins.py +++ b/tests/test_mixins.py @@ -1,3 +1,4 @@ +import tempfile import unittest import hazwaz @@ -33,5 +34,27 @@ class testEditorMixin(unittest.TestCase): ) +class MyCommand(hazwaz.MainCommand, hazwaz.mixins.ExternalEditorMixin): + """ + A command that edits a file + """ + + def main(self): + my_file = tempfile.NamedTemporaryFile() + self.edit_file_in_external_editor(my_file.name) + my_file.close() + + +class testCommandWithMixin(hazwaz.unittest.HazwazTestCase): + def test_run(self): + cmd = MyCommand() + cmd.editors = [("true", "true")] + stream = self.run_with_argv(cmd, [ + "mycommand", + ]) + self.assertEqual(stream["stdout"].getvalue(), "") + self.assertEqual(stream["stderr"].getvalue(), "") + + if __name__ == '__main__': unittest.main() -- cgit v1.2.3