"""Contains tests for finpack/core/cli.py
"""
__copyright__ = "Copyright (C) 2021 Matt Ferreira"

import os
import unittest
from importlib import metadata

from docopt import docopt

from finpack.core import cli


class TestCli(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.DATA_DIR = "temp"

        os.mkdir(cls.DATA_DIR)

    @classmethod
    def tearDownClass(cls):
        os.rmdir(cls.DATA_DIR)

    def test_version_option(self):
        argv = ["--version"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["--version"])

    def test_init_no_options(self):
        argv = ["init"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["init"])

    def test_init_with_filepath_option(self):
        argv = ["init", "--filepath=temp/data.csv"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["init"])
        self.assertEqual(args["--filepath"], "temp/data.csv")

    def test_init_with_sample_dataset_option(self):
        argv = ["init", "--sample-dataset"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["init"])
        self.assertTrue(args["--sample-dataset"])

    def test_init_with_overwrite_option(self):
        argv = ["init", "--overwrite"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["init"])
        self.assertTrue(args["--overwrite"])

    def test_balsheet_no_option(self):
        argv = ["balsheet"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["balsheet"])

    def test_balsheet_with_filepath_option(self):
        argv = ["balsheet", "--filepath=temp/data2.csv"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["balsheet"])
        self.assertEqual(args["--filepath"], "temp/data2.csv")

    def test_balsheet_with_levels_default(self):
        argv = ["balsheet"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["balsheet"])
        self.assertEqual(args["--levels"], "3")

    def test_balsheet_with_levels_option(self):
        argv = ["balsheet", "--levels=2"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["balsheet"])
        self.assertEqual(args["--levels"], "2")

    def test_balsheet_with_date_default(self):
        argv = ["balsheet"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["balsheet"])
        self.assertEqual(args["--date"], "today")

    def test_balsheet_with_date_option(self):
        argv = ["balsheet", "--date=2021-12-01"]

        args = docopt(cli.__doc__, argv=argv)

        self.assertTrue(args["balsheet"])
        self.assertEqual(args["--date"], "2021-12-01")

[((19, 8, 19, 30), 'os.mkdir', 'os.mkdir', ({(19, 17, 19, 29): 'cls.DATA_DIR'}, {}), '(cls.DATA_DIR)', False, 'import os\n'), ((23, 8, 23, 30), 'os.rmdir', 'os.rmdir', ({(23, 17, 23, 29): 'cls.DATA_DIR'}, {}), '(cls.DATA_DIR)', False, 'import os\n'), ((28, 15, 28, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((35, 15, 35, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((42, 15, 42, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((50, 15, 50, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((58, 15, 58, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((66, 15, 66, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((73, 15, 73, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((81, 15, 81, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((89, 15, 89, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((97, 15, 97, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n'), ((105, 15, 105, 45), 'docopt.docopt', 'docopt', (), '', False, 'from docopt import docopt\n')]