コード例 #1
0
ファイル: test_main.py プロジェクト: roryokane/td
class TestBehaviour(object):
    def setUp(self):
        self.mock = StdoutMock()
        Model.path = os.path.join(os.getcwd(), 'tests', 'data', 'tdtest1')

    def tearDown(self):
        self.mock.undo()

    def test_display_whole_list(self):
        self.mock.resetArgv()
        run()
        result = "{}{}{}{}{}{}\n".format(
            View.RESET, View.COLORS[3], View.BRIGHT, 1, '.', 'test'
        )
        self.mock.assertEqual(result)
コード例 #2
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
 def setUp(self):
     self.mock = StdoutMock()
     self.handler = HandlerMock()
     self.parser = Parser(ArgMock(), ["td"])
     self.parser._part = self.mock_part
     self.out = False
コード例 #3
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
class TestParserrock(object):
    def setUp(self):
        self.mock = StdoutMock()
        self.handler = HandlerMock()
        self.parser = Parser(ArgMock(), ["td"])
        self.parser._part = self.mock_part
        self.out = False

    def tearDown(self):
        self.mock.undo()

    def mock_part(self, *args, **kwargs):
        self.out = True

    def do_part(self, *n):
        self.parser.argv = deque(n)
        self.parser.rock()

    def assert_part(self, *n):
        self.do_part(*n)
        assert self.out is True

    def test_v(self):
        self.assert_part("v")

    def test_view(self):
        self.assert_part("view")

    def test_m(self):
        self.assert_part("m")

    def test_modify(self):
        self.assert_part("modify")

    def test_a(self):
        self.assert_part("a")

    def test_add(self):
        self.assert_part("add")

    def test_e_without_index(self):
        self.do_part("e")
        self.handler.assertLogged("edit: Not enough arguments.")

    def test_e(self):
        self.assert_part("e", "1.1")

    def test_edit(self):
        self.assert_part("edit", "1.1")

    def test_r_without_index(self):
        self.do_part("r")
        self.handler.assertLogged("rm: Not enough arguments.")

    def test_r(self):
        self.assert_part("r", "1.1")

    def test_rm(self):
        self.assert_part("rm", "1.1")

    def test_d_without_index(self):
        self.do_part("d")
        self.handler.assertLogged("done: Not enough arguments.")

    def test_d(self):
        self.assert_part("d", "1.1")

    def test_done(self):
        self.assert_part("done", "1.1")

    def test_D_without_index(self):
        self.do_part("D")
        self.handler.assertLogged("undone: Not enough arguments.")

    def test_D(self):
        self.assert_part("D", "1.1")

    def test_undone(self):
        self.assert_part("undone", "1.1")

    def test_o(self):
        self.assert_part("o")

    def test_options(self):
        self.assert_part("options")

    def test_add_parent(self):
        # It deserves a separate test
        self.assert_part("a", "1.1")

    def test_wrong_command(self):
        self.do_part("dang")
        self.handler.assertLogged("td: Unrecognized command [dang].")
コード例 #4
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
 def setUp(self):
     self.mock = StdoutMock()
     self.model = ModelMock()
     self.mock.resetArgv()
コード例 #5
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
class TestArg(object):
    def setUp(self):
        self.mock = StdoutMock()
        self.model = ModelMock()
        self.mock.resetArgv()

    def tearDown(self):
        self.mock.undo()

    def test_view(self):
        Arg(self.model)
        assert self.model.modify_val is True

    def test_modify(self):
        self.mock.addArgs("m", "-s", "sp", "-p", "-d", "dp", "-D", "Dp")
        Arg(self.model)
        assert self.model.modifyInPlace_val is True

    def test_add(self):
        self.mock.addArgs("a", "1.1", "-n", "n", "-p", "1", "-c", "c")
        Arg(self.model)
        assert self.model.add_val is True

    def test_edit(self):
        self.mock.addArgs("e", "1.1", "--parent", "2.2", "-n", "n", "-p", "1", "-c", "c")
        Arg(self.model)
        assert self.model.edit_val is True

    def test_rm(self):
        self.mock.addArgs("r", "1.1")
        Arg(self.model)
        assert self.model.rm_val is True

    def test_done(self):
        self.mock.addArgs("d", "1.1")
        Arg(self.model)
        assert self.model.done_val is True

    def test_undone(self):
        self.mock.addArgs("D", "1.1")
        Arg(self.model)
        assert self.model.undone_val is True

    def test_options(self):
        self.mock.addArgs("o", "-g", "-s", "sp", "-p", "-d", "dp", "-D", "Dp")
        Arg(self.model)
        assert self.model.options_val is True

    def test_options_sort(self):
        self.mock.addArgs("o", "-s")
        Arg(self.model)
        assert self.model.options_val is True

    def test_options_purge(self):
        self.mock.addArgs("o", "-p")
        Arg(self.model)
        assert self.model.options_val is True

    def test_options_done(self):
        self.mock.addArgs("o", "-d")
        Arg(self.model)
        assert self.model.options_val is True

    def test_options_undone(self):
        self.mock.addArgs("o", "-D")
        Arg(self.model)
        assert self.model.options_val is True

    def test_getKwargs(self):
        arg = Arg.__new__(Arg)
        result = arg.getKwargs({"priority": 3}, {"comment": "test"}, GetMock())
        assert result == {"name": "mock", "comment": "test", "priority": 3, "parent": "mock"}
コード例 #6
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
 def setUp(self):
     self.mock = StdoutMock()
     self.handler = HandlerMock()
     self.out1 = None
     self.out2 = None
コード例 #7
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
class TestParser_part(object):
    def setUp(self):
        self.mock = StdoutMock()
        self.handler = HandlerMock()
        self.out1 = None
        self.out2 = None

    def tearDown(self):
        self.mock.undo()

    def func1(self, test=None, sort=None):
        self.out1 = test

    def func2(self, test1=None, test2=None):
        self.out2 = (test1, test2)

    def test_help_message(self):
        parser = Parser("", ["td", "-h"])
        parser._part("test", "", {}, "help")
        self.mock.assertEqual("help\n")

    def test_one_argument(self):
        parser = Parser("", ["td", "-t", "value"])
        parser._part("test", self.func1, {"-t": ("test", True)}, "")
        assert self.out1 == "value"

    def test_argument_without_value(self):
        parser = Parser("", ["td", "-b"])
        parser._part("test", self.func1, {"-b": ("test", False)}, "")
        assert self.out1 is True

    def test_two_arguments(self):
        # It should break by induction further on.
        parser = Parser("", ["td", "-t1", "value1", "-t2", "value2"])
        parser._part("test", self.func2, {"-t1": ("test1", True), "-t2": ("test2", True)}, "")
        self.out2 == ("value1", "value2")

    def test_one_argument_for_two_arguments_func(self):
        parser = Parser("", ["td", "-t2", "value2"])
        parser._part("test", self.func2, {"-t1": ("test1", True), "-t2": ("test2", True)}, "")
        self.out2 == (None, "value2")

    def test_no_arguments(self):
        parser = Parser("", ["td"])
        parser._part("test", self.func1, {}, "", test=True)
        assert self.out1 is True

    def test_missing_argument(self):
        parser = Parser("", ["td", "-t"])
        parser._part("test", "", {"-t": ("test", True)}, "")
        self.handler.assertLogged("test: Not enough arguments.")

    def test_wrong_argument(self):
        parser = Parser("", ["td", "-y"])
        parser._part("test", "", {"-t": ("test", True)}, "")
        self.handler.assertLogged("test: Unrecognized argument [-y].")

    def test_sort_with_no_arguments(self):
        # If no arguments are supplied, it should use default.
        # Applies to done/undone too.
        parser = Parser("", ["td", "-s"])
        parser._part("test", self.func1, {"-s": ("sort", True)}, "", test=True)
        assert self.out1 is True
コード例 #8
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
 def setUp(self):
     self.mock = StdoutMock()
     self.get = Get()
     Get.input = self.func
     self.i = True
     self.v = ""
コード例 #9
0
ファイル: test_main.py プロジェクト: KenjiTakahashi/td
class TestGet(object):
    def setUp(self):
        self.mock = StdoutMock()
        self.get = Get()
        Get.input = self.func
        self.i = True
        self.v = ""

    def tearDown(self):
        self.mock.undo()

    def func(self, f):
        if self.i:
            self.i = False
            return self.v
        return "1"

    def test_correct_name(self):
        self.v = "test"
        result = self.get.get("name")
        assert result == "test"

    def test_empty_name(self):
        self.get.get("name")
        self.mock.assertEqual("Name cannot be empty.\n")

    def test_correct_comment(self):
        self.v = "test"
        result = self.get.get("comment")
        assert result == "test"

    def test_parent(self):
        # Anything is correct here. See docstring in the code.
        self.v = "1.1"
        result = self.get.get("parent")
        assert result == "1.1"

    def test_correct_priority_names(self):
        for n, ne in enumerate(["lowest", "low", "normal", "high", "highest"]):
            self.i = True
            self.v = ne
            result = self.get.get("priority")
            assert result == n + 1

    def test_incorrect_priority_name(self):
        self.v = "the highest"
        self.get.get("priority")
        self.mock.assertEqual("Unrecognized priority number or name [the highest].\n")

    def test_correct_priority_numbers(self):
        for n in range(1, 6):
            self.i = True
            self.v = str(n)
            result = self.get.get("priority")
            assert result == n

    def t_incorrect_priority_numbers(self, n):
        self.v = str(n)
        self.get.get("priority")
        self.mock.assertEqual("Unrecognized priority number or name [{}].\n".format(n))

    def test_incorrect_priority_number0(self):
        self.t_incorrect_priority_numbers(0)

    def test_incorrect_priority_number6(self):
        self.t_incorrect_priority_numbers(6)

    def test_empty_priority(self):
        result = self.get.get("priority")
        assert result is None
コード例 #10
0
ファイル: test_main.py プロジェクト: roryokane/td
 def setUp(self):
     self.mock = StdoutMock()
     Model.path = os.path.join(os.getcwd(), 'tests', 'data', 'tdtest1')