diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_commands.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py new file mode 100644 index 0000000..c948d69 --- /dev/null +++ b/tests/test_commands.py @@ -0,0 +1,56 @@ +import contextlib +import io +import tempfile +import unittest + +from lesana import command + + +class Args: + def __init__(self, args): + self.args = args + + def __getattribute__(self, k): + try: + return super().__getattribute__(k) + except AttributeError: + try: + return self.args[k] + except KeyError as e: + raise AttributeError(e) + + +class testCommands(unittest.TestCase): + def setUp(self): + self.collection_dir = tempfile.TemporaryDirectory() + + def tearDown(self): + pass + + def _edit_file(self, filepath): + return True + + def _run_command(self, cmd, args): + stream = { + 'stdout': io.StringIO(), + 'stderr': io.StringIO(), + } + cmd.edit_file_in_external_editor = self._edit_file + cmd.args = Args(args) + with contextlib.redirect_stdout(stream['stdout']): + with contextlib.redirect_stderr(stream['stderr']): + cmd.main() + return stream + + def test_init(self): + args = { + 'collection': self.collection_dir.name, + 'git': True, + } + streams = self._run_command(command.Init(), args) + self.assertEqual(streams['stdout'].getvalue(), '') + self.assertEqual(streams['stderr'].getvalue(), '') + + +if __name__ == '__main__': + unittest.main() |