# Path: librouteros/query.py
# class Query:
# 
#     def __init__(self, path, keys: typing.Sequence[Key], api):
#         self.path = path
#         self.keys = keys
#         self.api = api
#         self.query: typing.Tuple[str, ...] = tuple()
# 
#     def where(self, *args: str):
#         self.query = tuple(chain.from_iterable(args))
#         return self
# 
#     def __iter__(self) -> ResponseIter:
#         keys = ','.join(str(key) for key in self.keys)
#         keys = f'=.proplist={keys}'
#         cmd = str(self.path.join('print'))
#         return iter(self.api.rawCmd(cmd, keys, *self.query))
# 
# class Key:
# 
#     def __init__(self, name: str):
#         self.name = name
# 
#     def __eq__(self, other):
#         yield f'?={self}={cast_to_api(other)}'
# 
#     def __ne__(self, other):
#         yield from self == other
#         yield '?#!'
# 
#     def __lt__(self, other):
#         yield f'?<{self}={cast_to_api(other)}'
# 
#     def __gt__(self, other):
#         yield f'?>{self}={cast_to_api(other)}'
# 
#     def __str__(self) -> str:
#         return str(self.name)
# 
#     # pylint: disable=invalid-name
#     def In(self, one, *elems):
#         yield from self == one
#         yield from chain.from_iterable(self == str(elem) for elem in elems)
#         yield from ('?#|', ) * len(elems)
# 
# def And(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
#     #pylint: disable=invalid-name
#     yield from left
#     yield from right
#     yield from chain.from_iterable(rest)
#     yield '?#&'
#     yield from ('?#&', ) * len(rest)
# 
# def Or(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
#     #pylint: disable=invalid-name
#     yield from left
#     yield from right
#     yield from chain.from_iterable(rest)
#     yield '?#|'
#     yield from ('?#|', ) * len(rest)


import pytest
from unittest.mock import (MagicMock, patch)
from librouteros.query import (
    Query,
    Key,
    And,
    Or,
)

    def test_where_returns_self(self):
        assert self.query.where() == self.query

    def test_where_chains_from_args(self):
        self.query.where((1, 2, 3), (4, 5))
        assert self.query.query == (1, 2, 3, 4, 5)

    @patch('librouteros.query.iter')
    def test_iter_calls_api_rawCmd(self, iter_mock):
        self.query.keys = ('name', 'disabled')
        self.query.query = ('key1', 'key2')
        iter(self.query)
        self.query.api.rawCmd.assert_called_once_with(
            str(self.query.path.join.return_value),
            '=.proplist=name,disabled',
            'key1',
            'key2',
        )


class Test_Key:

    def setup(self):
        self.key = Key(name='key_name', )

    @pytest.mark.parametrize('param, expected', (
        (True, 'yes'),
        (False, 'no'),
        ('yes', 'yes'),

# Path: librouteros/query.py
# class Query:
# 
#     def __init__(self, path, keys: typing.Sequence[Key], api):
#         self.path = path
#         self.keys = keys
#         self.api = api
#         self.query: typing.Tuple[str, ...] = tuple()
# 
#     def where(self, *args: str):
#         self.query = tuple(chain.from_iterable(args))
#         return self
# 
#     def __iter__(self) -> ResponseIter:
#         keys = ','.join(str(key) for key in self.keys)
#         keys = f'=.proplist={keys}'
#         cmd = str(self.path.join('print'))
#         return iter(self.api.rawCmd(cmd, keys, *self.query))
# 
# class Key:
# 
#     def __init__(self, name: str):
#         self.name = name
# 
#     def __eq__(self, other):
#         yield f'?={self}={cast_to_api(other)}'
# 
#     def __ne__(self, other):
#         yield from self == other
#         yield '?#!'
# 
#     def __lt__(self, other):
#         yield f'?<{self}={cast_to_api(other)}'
# 
#     def __gt__(self, other):
#         yield f'?>{self}={cast_to_api(other)}'
# 
#     def __str__(self) -> str:
#         return str(self.name)
# 
#     # pylint: disable=invalid-name
#     def In(self, one, *elems):
#         yield from self == one
#         yield from chain.from_iterable(self == str(elem) for elem in elems)
#         yield from ('?#|', ) * len(elems)
# 
# def And(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
#     #pylint: disable=invalid-name
#     yield from left
#     yield from right
#     yield from chain.from_iterable(rest)
#     yield '?#&'
#     yield from ('?#&', ) * len(rest)
# 
# def Or(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
#     #pylint: disable=invalid-name
#     yield from left
#     yield from right
#     yield from chain.from_iterable(rest)
#     yield '?#|'
#     yield from ('?#|', ) * len(rest)


# Path: tests/unit/test_query.py
import pytest
from unittest.mock import (MagicMock, patch)
from librouteros.query import (
    Query,
    Key,
    And,
    Or,
)


    def test_where_returns_self(self):
        assert self.query.where() == self.query

    def test_where_chains_from_args(self):
        self.query.where((1, 2, 3), (4, 5))
        assert self.query.query == (1, 2, 3, 4, 5)

    @patch('librouteros.query.iter')
    def test_iter_calls_api_rawCmd(self, iter_mock):
        self.query.keys = ('name', 'disabled')
        self.query.query = ('key1', 'key2')
        iter(self.query)
        self.query.api.rawCmd.assert_called_once_with(
            str(self.query.path.join.return_value),
            '=.proplist=name,disabled',
            'key1',
            'key2',
        )


class Test_Key:

    def setup(self):
        self.key = Key(name='key_name', )

    @pytest.mark.parametrize('param, expected', (
        (True, 'yes'),
        (False, 'no'),
        ('yes', 'yes'),

        (1, '1'),