class Test_Api: def setup(self): self.api = Api(protocol=MagicMock()) @patch.object(Api, 'readResponse') @patch.object(ApiProtocol, 'writeSentence') def test_rawCmd_calls_writeSentence(self, writeSentence_mock, read_mock): args = ('/command', '=arg1=1', '=arg2=2') self.api.rawCmd(*args) assert writeSentence_mock.called_once_with(*args) @patch.object(Api, 'readResponse', return_value=(1, 2)) @patch.object(ApiProtocol, 'writeSentence') def test_rawCmd_returns_from_readResponse(self, writeSentence_mock, read_mock): assert tuple(self.api.rawCmd('/command', '=arg1=1', '=arg2=2')) == (1, 2)
class Test_Api: def setup(self): self.api = Api(protocol=MagicMock()) @pytest.mark.parametrize("path, expected", ( ("/ip/address/", "/ip/address"), ("ip/address", "/ip/address"), ("/ip/address", "/ip/address"), )) def test_joinPath_single_param(self, path, expected): assert self.api.joinPath(path) == expected @pytest.mark.parametrize("path, expected", ( (("/ip/address/", "print"), "/ip/address/print"), (("ip/address", "print"), "/ip/address/print"), (("/ip/address", "set"), "/ip/address/set"), (("/", "/ip/address", "set"), "/ip/address/set"), )) def test_joinPath_multi_param(self, path, expected): assert self.api.joinPath(*path) == expected
def setup(self): self.api = Api(protocol=MagicMock())
def test_api_path_returns_Path(): api = Api(protocol=MagicMock()) new = api.path('ip', 'address') assert new.path == '/ip/address' assert new.api == api assert isinstance(new, Path)