Exemple #1
0
    def __call__(self, args: typing.List[str], count: str) -> None:
        """Parse arguments and call func.

        Args:
            args: List of arguments for argparser to parse.
            count: Count passed to the command.
        """
        parsed_args = self.argparser.parse_args(args)
        kwargs = vars(parsed_args)
        self._parse_count(count, kwargs)
        objreg._call_with_instance(self.func, **kwargs)
Exemple #2
0
    def __call__(self, args: typing.List[str], count: str) -> None:
        """Parse arguments and call func.

        Args:
            args: List of arguments for argparser to parse.
            count: Count passed to the command.
        """
        if self._edit and settings.read_only:
            raise CommandError("Disabled due to read-only being active")
        parsed_args = self.argparser.parse_args(args)
        kwargs = vars(parsed_args)
        self._parse_count(count, kwargs)
        objreg._call_with_instance(self.func, **kwargs)
Exemple #3
0
def test_call_without_instance():
    def func(argument):
        return argument * 2

    argument = 42

    assert func(argument) == objreg._call_with_instance(func, argument)
Exemple #4
0
 def __call__(self) -> str:
     return objreg._call_with_instance(self._func)
Exemple #5
0
def test_call_with_instance(multiply_by_two):
    number = 42
    result = objreg._call_with_instance(Multiplier.multiply_by, number)
    assert result == 2 * number