From 6d116540dd06932ff8ba82e8f2b1f6559dec3698 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 23 Jul 2017 22:31:20 +1000 Subject: [PATCH] tests: Test args --- pywal/__main__.py | 6 +++--- tests/test_main.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/test_main.py diff --git a/pywal/__main__.py b/pywal/__main__.py index 566ff95..69908fe 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -24,7 +24,7 @@ from . import util from . import wallpaper -def get_args(): +def get_args(args): """Get the script arguments.""" description = "wal - Generate colorschemes on the fly" arg = argparse.ArgumentParser(description=description) @@ -62,7 +62,7 @@ def get_args(): arg.add_argument("-v", action="store_true", help="Print \"wal\" version.") - return arg.parse_args() + return arg.parse_args(args) def process_args(args): @@ -115,7 +115,7 @@ def process_args(args): def main(): """Main script function.""" - args = get_args() + args = get_args(sys.argv[1:]) process_args(args) # This saves 10ms. diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..8607933 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,37 @@ +"""Test __main__ functions.""" +import unittest +from pywal import __main__ + + +class TestMain(unittest.TestCase): + """Test the gen_colors functions.""" + + def test_no_args(self): + """> Generate a colorscheme and fail.""" + with self.assertRaises(SystemExit): + args = __main__.get_args([""]) + __main__.process_args(args) + + def test_conflict(self): + """> Test arg parsing (-i, -f)""" + with self.assertRaises(SystemExit): + args = __main__.get_args(["-i", "-f"]) + __main__.process_args(args) + + def test_version(self): + """> Test arg parsing (-v)""" + args = __main__.get_args(["-v"]) + self.assertTrue(args.v) + + def test_quiet(self): + """> Test arg parsing (-q)""" + args = __main__.get_args(["-q"]) + self.assertTrue(args.q) + + def test_ext_script(self): + """> Test arg parsing (-o)""" + args = __main__.get_args(["-o", "true"]) + self.assertTrue(args.o) + +if __name__ == "__main__": + unittest.main()