-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtestBeacon
executable file
·68 lines (57 loc) · 2.24 KB
/
testBeacon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
import sys, json, urllib2
import unittest
import imp
import os.path
if os.path.isfile("query"):
imp.load_source("query", "query") # hgBeacon does not have the .py extension
import query as hgBeacon
else:
imp.load_source("hgBeacon", "hgBeacon") # hgBeacon does not have the .py extension
import hgBeacon
baseUrl = None
if len(sys.argv)!=1:
baseUrl = sys.argv[1]
def queryServer(chrom, pos, allele, reference, dataset):
" if baseUrl is set, query via http. Otherwise just call the script directly "
if baseUrl == None:
ret = hgBeacon.lookupAlleleJson(chrom, pos, allele, reference, dataset)
else:
url = baseUrl+"?chromosome=%s&position=%s&allele=%s" % (chrom, str(pos), allele)
if reference!="":
url=url+"&reference=%s" % reference
if dataset!="":
url=url+"&dataset=%s" % dataset
data = urllib2.urlopen(url).read()
ret = json.loads(data)
return ret
class TestBeacon(unittest.TestCase):
def test_outside(self):
" test query, beacon "
maxInt = 2147483646
rep = queryServer("1", str(maxInt), "T", "", "test")
self.assertTrue(rep["query"]["position"]==maxInt)
self.assertTrue(rep["query"]["reference"]=="GRCh37")
self.assertTrue(rep["query"]["allele"]=="T")
self.assertTrue(rep["query"]["chromosome"]=="1")
self.assertTrue(rep["response"]["exists"]=="false")
bi = rep["beacon"]
self.assertTrue(bi["id"] != "")
self.assertTrue(bi["name"] != "")
self.assertTrue(bi["organization"] != "")
self.assertTrue(bi["description"] != "")
self.assertTrue(bi["api"] != "")
def test_allele(self):
" test true reply with the special testing chromosome"
pos = 0
rep = queryServer("test", str(pos), "A", "", "")
self.assertTrue(rep["response"]["exists"]=="true")
def test_allele_false(self):
" test false reply "
pos = 10000
rep = queryServer("test", str(pos), "A", "", "test")
self.assertTrue(rep["response"]["exists"]=="false")
#if __name__ == '__main__':
#unittest.main()
suite = unittest.TestLoader().loadTestsFromTestCase(TestBeacon)
unittest.TextTestRunner(verbosity=2).run(suite)