Skip to content

Commit

Permalink
Merge pull request aerospike#122 from citrusleaf/fix_python3_tests
Browse files Browse the repository at this point in the history
Fix python3 tests
  • Loading branch information
jboone100 committed Feb 10, 2016
2 parents 287b3e9 + ad1f302 commit 3da9ca0
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 473 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/new_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from test_base_class import TestBaseClass
from .test_base_class import TestBaseClass
aerospike = pytest.importorskip("aerospike")


Expand Down
94 changes: 42 additions & 52 deletions test/new_tests/test_append.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# -*- coding: utf-8 -*-
import pytest
import time
import sys
try:
import cPickle as pickle
except:
import pickle
from aerospike.exception import *
from .test_base_class import TestBaseClass
from aerospike import exception as e

aerospike = pytest.importorskip("aerospike")
try:
from aerospike.exception import *
import aerospike
except:
print("Please install aerospike python client.")
sys.exit(1)
Expand All @@ -24,7 +18,7 @@ def setup(self, request, as_connection):
"""
Setup Method
"""
for i in xrange(5):
for i in range(5):
key = ('test', 'demo', i)
rec = {'name': 'name%s' % (str(i)), 'age': i}
as_connection.put(key, rec)
Expand All @@ -37,7 +31,7 @@ def teardown():
"""
Teardown Method
"""
for i in xrange(5):
for i in range(5):
key = ('test', 'demo', i)
as_connection.remove(key)

Expand All @@ -53,7 +47,7 @@ def test_pos_append_with_correct_paramters(self):
key = ('test', 'demo', 1)
self.as_connection.append(key, "name", "str")

(key, meta, bins) = self.as_connection.get(key)
(key, _, bins) = self.as_connection.get(key)

assert bins == {'age': 1, 'name': 'name1str'}

Expand All @@ -62,12 +56,12 @@ def test_pos_append_with_correct_policies(self):
Invoke append() with correct policies
"""
key = ('test', 'demo', 1)
policy = {'timeout': 1000,
policy = {'timeout': 1000,
'retry': aerospike.POLICY_RETRY_ONCE,
'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER }
self.as_connection.append(key, "name", "str", {}, policy)

(key, meta, bins) = self.as_connection.get(key)
(key, _, bins) = self.as_connection.get(key)

assert bins == {'age': 1, 'name': 'name1str'}

Expand All @@ -84,7 +78,7 @@ def test_pos_append_with_policy_key_send(self):
}
self.as_connection.append(key, "name", "str", {}, policy)

(key, meta, bins) = self.as_connection.get(key)
(key, _, bins) = self.as_connection.get(key)

assert bins == {'age': 1, 'name': 'name1str'}
assert key == ('test', 'demo', None, bytearray(
Expand All @@ -107,7 +101,7 @@ def test_pos_append_with_policy_key_digest(self):
}
self.as_connection.append(key, "name", "str", {}, policy)

(key, meta, bins) = self.as_connection.get(key)
(key, _, bins) = self.as_connection.get(key)

assert bins == {'age': 1, 'name': 'name1str', 'nolist': [1, 2, 3]}
assert key == ('test', 'demo', None,
Expand Down Expand Up @@ -162,7 +156,6 @@ def test_pos_append_with_policy_key_gen_EQ_positive(self):
b'\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8')
)


def test_pos_append_with_policy_key_gen_GT_positive(self):
"""
Invoke append() with gen GT positive
Expand Down Expand Up @@ -194,7 +187,7 @@ def test_pos_append_with_nonexistent_key(self):
key = ('test', 'demo', 1000)
status = self.as_connection.append(key, "name", "str")

assert status == 0L
assert status == 0
self.as_connection.remove(key)

def test_pos_append_with_nonexistent_bin(self):
Expand All @@ -204,43 +197,41 @@ def test_pos_append_with_nonexistent_bin(self):
key = ('test', 'demo', 1)
status = self.as_connection.append(key, "name1", "str")

assert status == 0L
assert status == 0


def test_pos_append_unicode_value(self):
"""
Invoke append() with unicode string
"""
key = ('test', 'demo', 1)
res = self.as_connection.append(key, "name", u"address")
self.as_connection.append(key, "name", u"address")

key, meta, bins = self.as_connection.get(key)
key, _, bins = self.as_connection.get(key)
assert bins['name'] == 'name1address'

def test_pos_append_unicode_bin_name(self):
"""
Invoke append() with unicode string
"""
key = ('test', 'demo', 1)
res = self.as_connection.append(key, u"add", u"address")
self.as_connection.append(key, u"add", u"address")

key, meta, bins = self.as_connection.get(key)
key, _, bins = self.as_connection.get(key)
assert bins['add'] == 'address'


def test_pos_append_with_correct_timeout_policy(self):
"""
Invoke append() with correct policy
"""
key = ('test', 'demo', 1)
policy = {'gen': 5,
'timeout': 300,
'retry': aerospike.POLICY_RETRY_ONCE,
'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER
}
'timeout': 300,
'retry': aerospike.POLICY_RETRY_ONCE,
'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER
}
self.as_connection.append(key, "name", "str", {}, policy)

(key, meta, bins) = self.as_connection.get(key)
(key, _, bins) = self.as_connection.get(key)

assert bins == {'age': 1, 'name': 'name1str'}

Expand Down Expand Up @@ -270,14 +261,14 @@ def test_pos_append_with_bytearray_new_key(self):

self.as_connection.remove(key)

#Negative append tests
# Negative append tests
def test_neg_append_with_no_parameters(self):
"""
Invoke append() without any mandatory parameters.
"""
with pytest.raises(TypeError) as typeError:
self.as_connection.append()
assert "Required argument 'key' (pos 1) not found" in typeError.value
assert "Required argument 'key' (pos 1) not found" in str(typeError.value)

def test_neg_append_with_policy_key_gen_GT_lesser(self):
"""
Expand All @@ -300,10 +291,10 @@ def test_neg_append_with_policy_key_gen_GT_lesser(self):
}
try:
self.as_connection.append(key, "name", "str", meta, policy)
except RecordGenerationError as exception:
except e.RecordGenerationError as exception:
assert exception.code == 3
assert exception.bin == "name"
(key , meta, bins) = self.as_connection.get(key)
(key, meta, bins) = self.as_connection.get(key)
assert bins == {'age': 1, 'name': 'name1'}
assert key == ('test', 'demo', None, bytearray(
b'\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8')
Expand All @@ -330,11 +321,11 @@ def test_neg_append_with_policy_key_gen_EQ_not_equal(self):
try:
self.as_connection.append(key, "name", "str", meta, policy)

except RecordGenerationError as exception:
except e.RecordGenerationError as exception:
assert exception.code == 3
assert exception.bin == "name"

(key , meta, bins) = self.as_connection.get(key)
(key, meta, bins) = self.as_connection.get(key)

assert bins == {'age': 1, 'name': 'name1'}
assert key == ('test', 'demo', None, bytearray(
Expand All @@ -347,7 +338,7 @@ def test_neg_append_with_policy_key_gen_EQ_not_equal(self):
(('test', 'demo', 1), 3, "str", {}, {'gen': 5, 'timeout': 3000, 'retry':
aerospike.POLICY_RETRY_ONCE, 'commit_level':
aerospike.POLICY_COMMIT_LEVEL_MASTER}, -2, 'Bin name should be of type string'),
(('test', 'name'), "name", "str", {}, {"gen": 5}, -2,
(('test', 'name'), "name", "str", {}, {"gen": 5}, -2,
'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)'),
(('test', 'demo', 1), "name", "str", {}, {'timeout': 0.5}, -2, "timeout is invalid")
])
Expand All @@ -359,7 +350,7 @@ def test_neg_append_parameters_of_incorrect_types(self, key, bin, value,
try:
self.as_connection.append(key, bin, value, meta, policy)

except ParamError as exception:
except e.ParamError as exception:
assert exception.code == ex_code
assert exception.msg == ex_msg

Expand All @@ -372,7 +363,7 @@ def test_neg_append_with_extra_parameter(self):
with pytest.raises(TypeError) as typeError:
self.as_connection.append(key, "name", "str", {}, policy, "")

assert "append() takes at most 5 arguments (6 given)" in typeError.value
assert "append() takes at most 5 arguments (6 given)" in str(typeError.value)

@pytest.mark.parametrize("key, bin, ex_code, ex_msg", [
(None, "name", -2, "key is invalid"),
Expand All @@ -385,7 +376,7 @@ def test_neg_append_parameters_as_none(self, key, bin, ex_code, ex_msg):
try:
self.as_connection.append(key, bin, "str")

except ParamError as exception:
except e.ParamError as exception:
assert exception.code == ex_code
assert exception.msg == ex_msg

Expand All @@ -400,8 +391,8 @@ def test_neg_append_with_correct_parameters_without_connection(self):
try:
client1.append(key, "name", "str")

except ClusterError as exception:
assert exception.code == 11L
except e.ClusterError as exception:
assert exception.code == 11

def test_neg_append_with_low_timeout(self):

Expand All @@ -410,25 +401,24 @@ def test_neg_append_with_low_timeout(self):
"""
key = ('test', 'demo', 1)
policy = {'gen': 5,
'timeout': 1,
#'retry': aerospike.POLICY_RETRY_ONCE,
'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER
}
'timeout': 1,
# 'retry': aerospike.POLICY_RETRY_ONCE,
'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER
}
try:
self.as_connection.append(key, "name", "str", {}, policy)
except TimeoutError as exception:
assert exception.code == 9L
except e.TimeoutError as exception:
assert exception.code == 9

def test_neg_append_with_non_existent_ns(self):
"""
Invoke append() with non existent ns
"""
key = ('test1', 'demo', 'name')
policy = {'gen': 5,
'timeout': 300,
}
'timeout': 300,
}
try:
self.as_connection.append(key, "name", "str", {}, policy)
except NamespaceNotFound as exception:
assert exception.code == 20L

except e.NamespaceNotFound as exception:
assert exception.code == 20
8 changes: 5 additions & 3 deletions test/new_tests/test_base_class.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import ConfigParser

try:
import ConfigParser as configparser
except:
import configparser

class TestBaseClass(object):
hostlist = []
Expand All @@ -11,7 +13,7 @@ class TestBaseClass(object):

@staticmethod
def get_hosts():
config = ConfigParser.ConfigParser()
config = configparser.ConfigParser()
config.read("config.conf")
if config.has_option('enterprise-edition', 'hosts'):
hosts_str = config.get('enterprise-edition','hosts')
Expand Down
19 changes: 8 additions & 11 deletions test/new_tests/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import pytest
import sys
try:
import cPickle as pickle
except:
import pickle
from .test_base_class import TestBaseClass

aerospike = pytest.importorskip("aerospike")
try:
from aerospike.exception import *
import aerospike
from aerospike import exception as e
except:
print("Please install aerospike python client.")
sys.exit(1)
Expand All @@ -24,13 +21,13 @@ def test_pos_close(self):
Invoke close() after positive connect
"""
config = {'hosts': TestBaseClass.hostlist}
if TestClose.user == None and TestClose.password == None:
if TestClose.user is None and TestClose.password is None:
self.client = aerospike.client(config).connect()
else:
self.client = aerospike.client(config).connect(TestClose.user,
TestClose.password)
self.closeobject = self.client.close()
assert self.closeobject == None
assert self.closeobject is None

def test_pos_close_without_connection(self):
"""
Expand All @@ -42,19 +39,19 @@ def test_pos_close_without_connection(self):
try:
self.closeobject = self.client.close()

except ClusterError as exception:
assert exception.code == 11L
except e.ClusterError as exception:
assert exception.code == 11

def test_neg_close(self):
"""
Invoke close() after negative connect
"""
config = {'hosts': [('127.0.0.1', 2000)]}

with pytest.raises(Exception) as exception:
with pytest.raises(Exception):
self.client = aerospike.client(config).connect()
with pytest.raises(AttributeError) as attributeError:
self.closeobject = self.client.close()
assert "TestClose instance has no attribute 'client'" in attributeError.value
assert "has no attribute" in str(attributeError.value)


Loading

0 comments on commit 3da9ca0

Please sign in to comment.