def test_connect(self): # test the connect grn = Groonga() grn.connect(host='localhost', port=10041) self.assertTrue(grn.connected) self.assertEqual(grn.host, 'localhost') self.assertEqual(grn.port, 10041)
def test_reconnect(self): grn = Groonga() ctx = grn._ctx assert grn._ctx is ctx assert grn.connected is False grn.reconnect() assert grn._ctx is not ctx assert grn.connected is True
def test__raise_if_notsuccess(self): grn = Groonga() try: grn._raise_if_notsuccess(_groonga.SUCCESS) except GroongaError: self.fail("GroongaError has been raised") from pyroonga.exceptions import error_messages for rc in [rc for rc in error_messages if rc != _groonga.SUCCESS]: self.assertRaises(GroongaError, grn._raise_if_notsuccess, rc)
def test_connect_with_params(self): grn = Groonga() assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect(host='localhost', port=10041) assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041
def test_connect_with_default(self): grn = Groonga() assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect() assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041
def test_connect_with_default(self): grn = Groonga() grn._ctx = mock.MagicMock() grn._ctx.connect.return_value = 0 assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect() assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041 assert grn._ctx.connect.mock_calls == [mock.call('0.0.0.0', 10041, flags=0)]
def test_connect_with_params(self): host = utils.random_string() port = random.randint(1025, 65535) grn = Groonga() grn._ctx = mock.MagicMock() grn._ctx.connect.return_value = 0 assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect(host=host, port=port) assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041 assert grn._ctx.connect.mock_calls == [mock.call(host, port, flags=0)]
def test_query_with_after_invalid_command(self): grn = Groonga() grn.connect() with pytest.raises(GroongaError): grn.query('unknown command') result = grn.query('cache_limit') assert result == '100'
def test_reconnect(self): # test the reconnect with not connected grn = Groonga() ctx = grn._ctx self.assertRaises(GroongaError, grn.reconnect) self.assertIs(grn._ctx, ctx) self.assertFalse(grn.connected) # test the reconnect grn = Groonga() ctx = grn._ctx grn.host = 'localhost' grn.port = 10041 grn.reconnect() self.assertIsNot(grn._ctx, ctx) self.assertTrue(grn.connected)
def test__raise_if_notsuccess_with_not_success(self, rc): grn = Groonga() with pytest.raises(GroongaError): grn._raise_if_notsuccess(rc, "", "")
def test__raise_if_notsuccess_with_success(self): grn = Groonga() try: grn._raise_if_notsuccess(_groonga.SUCCESS, "", "") except GroongaError: assert False, "GroongaError has been raised"
def test_query(self): # test with not connected grn = Groonga() self.assertRaises(GroongaError, grn.query, 'a') # test with invalid command grn = Groonga() grn.connect('localhost', 10041) self.assertRaises(GroongaError, grn.query, 'a') # test the query grn = Groonga() grn.connect('localhost', 10041) result = grn.query('table_list') self.assertEqual(result, '''[[["id","UInt32"],["name","ShortText"],\ ["path","ShortText"],["flags","ShortText"],["domain","ShortText"],\ ["range","ShortText"]]]''') # test the query with after the query of invalid command grn = Groonga() grn.connect('localhost', 10041) self.assertRaises(GroongaError, grn.query, 'unknown command') result = grn.query('table_list') self.assertEqual(result, '''[[["id","UInt32"],["name","ShortText"],\ ["path","ShortText"],["flags","ShortText"],["domain","ShortText"],\ ["range","ShortText"]]]''')
def test_query(self): grn = Groonga() grn.connect() result = grn.query('cache_limit') assert result == '100'
def test_query_with_invalid_command(self): grn = Groonga() grn.connect() with pytest.raises(GroongaError): grn.query('a')
def test_query_with_not_connected(self): grn = Groonga() with pytest.raises(GroongaError): grn.query('a')
def test_connect_with_incorrect_params(self, host, port): grn = Groonga() with pytest.raises(GroongaError): grn.connect(host=host, port=port)