aboutsummaryrefslogtreecommitdiff
path: root/tests/test_commands.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-03-24 09:51:10 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-03-24 09:51:10 +0100
commit1014eccda2a99e68aa64fdc11920470a68bab207 (patch)
treefcafe3de84f11517edb00c612d591f6aac424d77 /tests/test_commands.py
parent0def616f189ed5bdbbe1db7dc59a3c6cfca6f51e (diff)
Start writing some tests for the command line classes
Diffstat (limited to 'tests/test_commands.py')
-rw-r--r--tests/test_commands.py56
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()