Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bio.Cluster not checking arguments under Python 3 #340

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Bio/Cluster/clustermodule.c
Expand Up @@ -44,7 +44,7 @@ distance_converter(PyObject* object, void* pointer)
return 0;
}
if (strlen(data)!=1)
{ PyErr_SetString(PyExc_ValueError, "distance should be a single character");
{ PyErr_Format(PyExc_ValueError, "distance should be a single character (not '%s')", data);
return 0;
}
c = data[0];
Expand Down Expand Up @@ -73,7 +73,7 @@ method_treecluster_converter(PyObject* object, void* pointer)
return 0;
}
if (strlen(data)!=1)
{ PyErr_SetString(PyExc_ValueError, "method should be a single character");
{ PyErr_Format(PyExc_ValueError, "method should be a single character (not '%s')", data);
return 0;
}
c = data[0];
Expand Down Expand Up @@ -102,7 +102,7 @@ method_kcluster_converter(PyObject* object, void* pointer)
return 0;
}
if (strlen(data)!=1)
{ PyErr_SetString(PyExc_ValueError, "method should be a single character");
{ PyErr_Format(PyExc_ValueError, "method should be a single character (not '%s')", data);
return 0;
}
c = data[0];
Expand Down Expand Up @@ -131,7 +131,7 @@ method_clusterdistance_converter(PyObject* object, void* pointer)
return 0;
}
if (strlen(data)!=1)
{ PyErr_SetString(PyExc_ValueError, "method should be a single character");
{ PyErr_Format(PyExc_ValueError, "method should be a single character (not '%s')", data);
return 0;
}
c = data[0];
Expand Down
72 changes: 72 additions & 0 deletions Tests/test_Cluster.py
Expand Up @@ -135,6 +135,19 @@ def test_kcluster(self):
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1]], int)

#TODO - Use a context manager here once we drop Python 2.6
#Method should be one letter:
self.assertRaises(ValueError, kcluster, data,
**{"nclusters": nclusters, "mask": mask,
"weight": weight, "transpose": 0, "npass": 100,
"method": "any", "dist": "e"})

#Distance should be one letter:
self.assertRaises(ValueError, kcluster, data,
**{"nclusters": nclusters, "mask": mask,
"weight": weight, "transpose": 0, "npass": 100,
"method": "a", "dist": "euclidean"})

clusterid, error, nfound = kcluster(data, nclusters=nclusters,
mask=mask, weight=weight,
transpose=0, npass=100,
Expand Down Expand Up @@ -175,6 +188,19 @@ def test_kcluster(self):
[ 1, 1 ],
[ 1, 1 ]], int)

#TODO - Use a context manager here once we drop Python 2.6
#Method should be one letter:
self.assertRaises(ValueError, kcluster, data,
**{"nclusters": 3, "mask": mask,
"weight": weight, "transpose": 0, "npass": 100,
"method": "any", "dist": "e"})

#Distance should be one letter:
self.assertRaises(ValueError, kcluster, data,
**{"nclusters": 3, "mask": mask,
"weight": weight, "transpose": 0, "npass": 100,
"method": "a", "dist": "euclidean"})

clusterid, error, nfound = kcluster(data, nclusters=3, mask=mask,
weight=weight, transpose=0,
npass=100, method='a', dist='e')
Expand Down Expand Up @@ -207,6 +233,19 @@ def test_clusterdistance(self):
c2 = [1, 2]
c3 = [3]

#TODO - Use a context manager here once we drop Python 2.6
#Method should be one letter:
self.assertRaises(ValueError, clusterdistance, data,
**{"mask": mask, "weight": weight,
"index1": c1, "index2": c2, "transpose": 0,
"method": "any", "dist": "e"})

#Distance should be one letter:
self.assertRaises(ValueError, clusterdistance, data,
**{"mask": mask, "weight": weight,
"index1": c1, "index2": c2, "transpose": 0,
"method": "a", "dist": "euclidean"})

distance = clusterdistance(data, mask=mask, weight=weight,
index1=c1, index2=c2, dist='e',
method='a', transpose=0)
Expand Down Expand Up @@ -254,6 +293,21 @@ def test_clusterdistance(self):
c2 = [ 4, 5, 6, 7 ]
c3 = [ 8 ]

#TODO - Use a context manager here once we drop Python 2.6
#Method should be one letter:
self.assertRaises(ValueError, clusterdistance, data,
**{"mask": mask, "weight": weight,
"index1": c1, "index2": c2,
"method": "any", "dist": "e",
"transpose":0})

#Distance should be one letter:
self.assertRaises(ValueError, clusterdistance, data,
**{"mask": mask, "weight": weight,
"index1": c1, "index2": c2,
"method": "a", "dist": "euclidena",
"transpose":0})

distance = clusterdistance(data, mask=mask, weight=weight,
index1=c1, index2=c2, dist='e',
method='a', transpose=0)
Expand Down Expand Up @@ -284,6 +338,17 @@ def test_treecluster(self):
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1]], int)

#TODO - Use a context manager here once we drop Python 2.6
#Method should be one letter:
self.assertRaises(ValueError, treecluster,
**{"data": data1, "mask": mask1, "weight": weight1,
"transpose":0, "method": "any", "dist": "e"})

#Distance should be one letter:
self.assertRaises(ValueError, treecluster,
**{"data": data1, "mask": mask1, "weight": weight1,
"transpose":0, "method": "any", "dist": "euclidean"})

# test first data set
# Pairwise average-linkage clustering"
tree = treecluster(data=data1, mask=mask1, weight=weight1,
Expand Down Expand Up @@ -552,6 +617,13 @@ def test_somcluster(self):
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1]], int)

#TODO - Use a context manager here once we drop Python 2.6
#Distance should be one letter:
self.assertRaises(ValueError, somcluster,
**{"data": data, "mask": mask, "weight": weight,
"transpose": 0, "nxgrid": 10, "nygrid": 10,
"inittau": 0.02, "niter": 100, "dist": "euclidean"})

clusterid, celldata = somcluster(data=data, mask=mask, weight=weight,
transpose=0, nxgrid=10, nygrid=10,
inittau=0.02, niter=100, dist='e')
Expand Down