Пример #1
0
    def test_handle_label_calls(self):
        """
        Assert handle_label is called for every argument.
        """
        cmd = LabelCommand(label="foo")

        # Mock the laberl command
        cmd.handle_label = mock.MagicMock(return_value="b")

        # Create subparsers
        primary = argparse.ArgumentParser()
        subparsers = primary.add_subparsers()

        # Create the parser
        parser = cmd.create_parser(subparsers)
        labels = ['baz', 'bar', 'biz', 'byr']
        args   = parser.parse_args(labels)

        # Call the handle method with the args
        output = cmd.handle(args)

        # Assert the mock method was called
        self.assertEqual(cmd.handle_label.call_count, len(labels))

        # Assert the mock was called with each label and args
        cmd.handle_label.assert_has_calls([
            mock.call(label, args)
            for label in labels
        ])

        # Check output is the newline joined string values
        self.assertEqual(output, "b\nb\nb\nb")
Пример #2
0
 def test_handle_interface(self):
     """
     Assert that handle_label raises an interface error.
     """
     with self.assertRaises(NotImplementedError):
         cmd = LabelCommand()
         cmd.handle_label({})
Пример #3
0
    def test_handle_label_calls(self):
        """
        Assert handle_label is called for every argument.
        """
        cmd = LabelCommand(label="foo")

        # Mock the laberl command
        cmd.handle_label = mock.MagicMock(return_value="b")

        # Create subparsers
        primary = argparse.ArgumentParser()
        subparsers = primary.add_subparsers()

        # Create the parser
        parser = cmd.create_parser(subparsers)
        labels = ['baz', 'bar', 'biz', 'byr']
        args = parser.parse_args(labels)

        # Call the handle method with the args
        output = cmd.handle(args)

        # Assert the mock method was called
        self.assertEqual(cmd.handle_label.call_count, len(labels))

        # Assert the mock was called with each label and args
        cmd.handle_label.assert_has_calls(
            [mock.call(label, args) for label in labels])

        # Check output is the newline joined string values
        self.assertEqual(output, "b\nb\nb\nb")
Пример #4
0
 def test_handle_interface(self):
     """
     Assert that handle_label raises an interface error.
     """
     with self.assertRaises(NotImplementedError):
         cmd = LabelCommand()
         cmd.handle_label({})
Пример #5
0
    def test_add_label_argument(self):
        """
        Test the default addition of the label.
        """
        cmd = LabelCommand(label="foo")

        # Create subparsers
        primary = argparse.ArgumentParser()
        subparsers = primary.add_subparsers()

        # Create the parser
        parser = cmd.create_parser(subparsers)
        args = parser.parse_args(['baz', 'bar', 'biz', 'byr'])

        self.assertEqual(args.labels, ['baz', 'bar', 'biz', 'byr'])
Пример #6
0
    def test_add_label_argument(self):
        """
        Test the default addition of the label.
        """
        cmd = LabelCommand(label="foo")

        # Create subparsers
        primary = argparse.ArgumentParser()
        subparsers = primary.add_subparsers()

        # Create the parser
        parser = cmd.create_parser(subparsers)
        args = parser.parse_args(['baz', 'bar', 'biz', 'byr'])

        self.assertEqual(args.labels, ['baz', 'bar', 'biz', 'byr'])