From ec39e4fd645148a839c1e2829bb074f02687ead4 Mon Sep 17 00:00:00 2001 From: Tycho Pandelaar Date: Mon, 9 Oct 2023 17:25:07 +0200 Subject: [PATCH] Initial tests --- tests/test_main.py | 41 +++++++++++++++++++++++++++++++++++++ tests/test_table.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 tests/test_main.py create mode 100644 tests/test_table.py diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..afa8712 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,41 @@ +import unittest +from main import show_usage + + +class TestMain(unittest.TestCase): + + def test_show_usage(self): + expected_usage = """ +Usage: + `gitgrove COMMAND` + + or one of the shortcuts: + `gg COMMAND`, `ggs`, `ggf`, `ggp`, `ggpr`, `ggc`, `ggb BRANCH`, `ggd` + +Commands: + -s, --status : Show all the repository statuses. + -f, --fetch : Fetch all repositories. + -p, --pull : Pull all repositories. + -pr, --prune : Prunes objects that are no longer reachable. + -c, --cleanup : Clean up and optimize the local repositories. + -b, --branch BRANCH: Switch all repositories to a specified branch. + -d, --development : Switch all repositories to the development branch. + +Shortcuts: + gg : Same as gitgrove. + ggs : Show all the repository statuses. + ggf : Fetch all repositories. + ggp : Pull all repositories. + ggpr : Prunes objects that are no longer reachable. + ggc : Clean up and optimize the local repositories. + ggb BRANCH: Switch all repositories to a specified branch. + ggd : Switch all repositories to the development branch. +""" + + actual_usage = show_usage() + + self.assertEqual(expected_usage, actual_usage) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_table.py b/tests/test_table.py new file mode 100644 index 0000000..f80e0d1 --- /dev/null +++ b/tests/test_table.py @@ -0,0 +1,49 @@ +import unittest +from table import Table, Cell, TableRenderer + + +class TestCell(unittest.TestCase): + + def test_init(self): + cell = Cell("Hello, world!") + + self.assertEqual(cell.content, "Hello, world!") + self.assertEqual(cell.justify, "left") + self.assertEqual(cell.color, ANSI_WHITE) + + cell = Cell("Hello, world!", justify="right", color=ANSI_RED) + + self.assertEqual(cell.content, "Hello, world!") + self.assertEqual(cell.justify, "right") + self.assertEqual(cell.color, ANSI_RED) + + +class TestTable(unittest.TestCase): + + def test_init(self): + table = Table() + self.assertEqual(table.rows, []) + + +class TestTableIntegration(unittest.TestCase): + + def test_render_table(self): + table = Table() + table.add_row(["Name", "Age"]) + table.add_row(["John Doe", 30]) + + renderer = TableRenderer(table, ANSI_GREY, ANSI_WHITE) + rendered_table = renderer.render() + + expected_rendered_table = """ + ╔═══════╦═══════╗ + ║ Name ║ Age ║ + ╠═══════╬═══════╣ + ║ John Doe ║ 30 ║ + ╚═══════╩═══════╝ +""" + + self.assertEqual(rendered_table, expected_rendered_table) + +if __name__ == '__main__': + unittest.main()