Skip to content

Commit

Permalink
lint more tests (#86)
Browse files Browse the repository at this point in the history
* better roadmap

* Remove unused imports

* fix block comments

* fix too long

* fix "never used"... but it is clear there are tests that do nothing.

* "flake8 test/*.py" is clean
  • Loading branch information
mccalluc authored and pkerpedjiev committed May 24, 2019
1 parent dafc422 commit e6f6f9d
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 104 deletions.
54 changes: 32 additions & 22 deletions test/bedfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import os.path as op
import sqlite3
import sys
import tempfile

testdir = op.realpath(op.dirname(__file__))
Expand Down Expand Up @@ -38,7 +37,11 @@ def check_table(filename):
'''

rows = c.execute(
'SELECT * from intervals,position_index where intervals.id=position_index.id and zoomLevel < 1 and rStartPos > 2400000000 and rEndPos < 2500000000')
'SELECT * from intervals,position_index '
'where intervals.id=position_index.id '
'and zoomLevel < 1 '
'and rStartPos > 2400000000 '
'and rEndPos < 2500000000')
counter = 0
for row in rows:
assert(row[3] > 2400000000)
Expand All @@ -51,12 +54,13 @@ def check_table(filename):
def test_get_tiles():
filename = 'test/sample_data/gene_annotations.short.db'

tiles = cdt.get_tiles(filename, 18, 169283)[169283]

cdt.get_tiles(filename, 18, 169283)[169283]
# TODO: Make assertions about result
# print("tiles:", tiles)
x = int(tiles[0]['xStart'])

fields = tiles[0]['fields']
# x = int(tiles[0]['xStart'])
#
# fields = tiles[0]['fields']
# TODO: Make assertions


def test_gene_annotations():
Expand All @@ -71,7 +75,7 @@ def test_gene_annotations():
'--delimiter', '\t',
'--assembly', 'mm10', '--output-file', f.name])

import traceback
# import traceback
a, b, tb = result.exc_info
'''
print("exc_info:", result.exc_info)
Expand Down Expand Up @@ -106,7 +110,7 @@ def test_random_importance():
'--max-per-tile', '2', '--importance-column', 'random',
'--assembly', 'b37', '--has-header', '--output-file', f.name])

import traceback
# import traceback
a, b, tb = result.exc_info
'''
print("exc_info:", result.exc_info)
Expand All @@ -116,17 +120,21 @@ def test_random_importance():
print("Exception:", a,b)
'''

tileset_info = cdt.get_tileset_info(f.name)
cdt.get_tileset_info(f.name)
# print("tileset_info:", tileset_info)
# TODO: Make assertions about result

rows = cdt.get_tiles(f.name, 0, 0)
#print("rows:", rows)
cdt.get_tiles(f.name, 0, 0)
# print("rows:", rows)
# TODO: Make assertions about result

rows = list(cdt.get_tiles(f.name, 1, 0).values()) + \
list(cdt.get_tiles(f.name, 1, 0).values()) + \
list(cdt.get_tiles(f.name, 1, 1).values())
#print('rows:', rows)
# print('rows:', rows)
# TODO: Make assertions about result

# check to make sure that tiles in the higher zoom levels are all present in lower zoom levels
# check to make sure that tiles in the higher zoom levels
# are all present in lower zoom levels
found = {}
for row in cdt.get_tiles(f.name, 5, 15).values():
for rect in row:
Expand All @@ -143,7 +151,7 @@ def test_random_importance():
found[rect['xStart']] = True

for key, value in found.items():
assert(value == True)
assert(value)

pass

Expand All @@ -162,7 +170,7 @@ def test_no_chromosome_limit():
'--assembly', 'hg19',
'--output-file', f.name])

import traceback
# import traceback
'''
print("exc_info:", result.exc_info)
print("result:", result)
Expand All @@ -183,7 +191,7 @@ def test_no_chromosome_limit():
foundOther = True
break
# make sure there's chromosome other than 14 in the output
assert(foundOther == True)
assert(foundOther)

os.remove(f.name)
pass
Expand All @@ -196,16 +204,16 @@ def test_chromosome_limit():
input_file = op.join(testdir, 'sample_data',
'geneAnnotationsExonsUnions.short.bed')

result = runner.invoke(
runner.invoke(
cca.bedfile,
[input_file,
'--max-per-tile', '60', '--importance-column', '5',
'--assembly', 'hg19', '--chromosome', 'chr14',
'--output-file', f.name])
# TODO: Make assertions about result

# print('output:', result.output, result)
rows = cdt.get_tiles(f.name, 0, 0)[0]
foundOther = False

for row in rows:
assert(row['fields'][0] == 'chr14')
Expand All @@ -220,11 +228,12 @@ def test_float_importance():
runner = clt.CliRunner()
input_file = op.join(testdir, 'sample_data', 'test_float_importance.bed')

result = runner.invoke(
runner.invoke(
cca.bedfile,
[input_file,
'--max-per-tile', '2', '--importance-column', '4',
'--assembly', 'hg38', '--no-header', '--output-file', f.name])
# TODO: Make assertions about result


"""
Expand Down Expand Up @@ -279,7 +288,8 @@ def test_tile_ranges():
d1 = cht.get_discrete_data(f, 11, 5)
#print("d1:", len(d1))
#print("dv:", [x for x in d1 if (int(x[1]) < 12000000 and int(x[2]) > 12000000)])
#print("dv:", [x for x in d1 if (int(x[1]) < 12000000
# and int(x[2]) > 12000000)])
d3 = cht.get_discrete_data(f, 12, 10)
#print("d2:", len(d3))
Expand Down
23 changes: 11 additions & 12 deletions test/bedpe_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from __future__ import print_function

import clodius.db_tiles as cdt
import click.testing as clt
import clodius.cli.aggregate as cca
import h5py
import negspy.coordinates as nc
import os.path as op
import sys

Expand All @@ -31,21 +28,23 @@ def test_clodius_aggregate_bedpe():
[input_file,
'--output-file', output_file,
'--importance-column', 'random',
'--has-header',
'--has-header',
'--assembly', 'b37'])
#print('output:', result.output, result)
assert(result.exit_code == 0)
"""

entries = cdt.get_2d_tiles(output_file, 0, 0, 0)
#print("entries:", entries)
cdt.get_2d_tiles(output_file, 0, 0, 0)
# print("entries:", entries)

tileset_info = cdt.get_tileset_info(output_file)
#print('tileset_info', tileset_info)
cdt.get_tileset_info(output_file)
# TODO: Make assertions about result
# print('tileset_info', tileset_info)

entries = cdt.get_2d_tiles(output_file, 1, 0, 0, numx=2, numy=2)
#print("entries:", entries)
cdt.get_2d_tiles(output_file, 1, 0, 0, numx=2, numy=2)
# TODO: Make assertions about result
# print("entries:", entries)

tileset_info = cdt.get_tileset_info(output_file)
#print('tileset_info', tileset_info)
cdt.get_tileset_info(output_file)
# TODO: Make assertion
85 changes: 42 additions & 43 deletions test/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np
import os.path as op
import sys
import traceback

sys.path.append("scripts")

Expand Down Expand Up @@ -42,7 +41,7 @@ def test_clodius_aggregate_bedfile():
assert(result.exit_code == 0)

results = cdt.get_tiles(output_file, 6, 3, num_tiles=1)
#print("results:", results)
# print("results:", results)

assert(len(results[3][0]['fields']) == 14)

Expand Down Expand Up @@ -76,7 +75,7 @@ def test_clodius_aggregate_bedgraph():
cca.bedgraph,
[input_file,
'--output-file', output_file,
#'--assembly', 'grch37',
# '--assembly', 'grch37',
'--chromsizes-filename', assembly_file,
'--chromosome-col', '2',
'--from-pos-col', '3',
Expand All @@ -92,7 +91,7 @@ def test_clodius_aggregate_bedgraph():
[input_file,
'--output-file', output_file,
'--assembly', 'grch37',
#'--chromsizes-filename', assembly_file,
# '--chromsizes-filename', assembly_file,
'--chromosome-col', '2',
'--from-pos-col', '3',
'--to-pos-col', '4',
Expand All @@ -112,49 +111,51 @@ def test_clodius_aggregate_bedgraph():

assert(result.exit_code == 0)
f = h5py.File(output_file)
#print("tile_0_0", d)
# print("tile_0_0", d)

#print("tile:", cht.get_data(f, 22, 0))
# print("tile:", cht.get_data(f, 22, 0))
# return
d = cht.get_data(f, 0, 0)

assert(not np.isnan(d[0]))
assert(np.isnan(d[-1]))
prev_tile_3_0 = cht.get_data(f, 3, 0)
cht.get_data(f, 3, 0)
# TODO: Make assertions about result

#print("prev_tile_3_0:", prev_tile_3_0)
# print("prev_tile_3_0:", prev_tile_3_0)

assert(result.exit_code == 0)
return
assert(sum(prev_tile_3_0) < 0)

input_file = op.join(testdir, 'sample_data', 'cnvs_hw.tsv.gz')
result = runner.invoke(
cca.bedgraph,
[input_file,
'--output-file', output_file,
'--assembly', 'grch37',
'--chromosome-col', '2',
'--from-pos-col', '3',
'--to-pos-col', '4',
'--value-col', '5',
'--has-header',
'--nan-value', 'NA'])

'''
import traceback
print("exc_info:", result.exc_info)
a,b,tb = result.exc_info
print("result:", result)
print("result.output", result.output)
print("result.error", traceback.print_tb(tb))
print("Exception:", a,b)
'''

f = h5py.File(output_file)
tile_3_0 = cht.get_data(f, 3, 0)

assert(sum(tile_3_0) - sum(prev_tile_3_0) < 0.0001)
# TODO: Why are we ignoring these?
# assert(sum(prev_tile_3_0) < 0)
#
# input_file = op.join(testdir, 'sample_data', 'cnvs_hw.tsv.gz')
# result = runner.invoke(
# cca.bedgraph,
# [input_file,
# '--output-file', output_file,
# '--assembly', 'grch37',
# '--chromosome-col', '2',
# '--from-pos-col', '3',
# '--to-pos-col', '4',
# '--value-col', '5',
# '--has-header',
# '--nan-value', 'NA'])
#
# '''
# import traceback
# print("exc_info:", result.exc_info)
# a,b,tb = result.exc_info
# print("result:", result)
# print("result.output", result.output)
# print("result.error", traceback.print_tb(tb))
# print("Exception:", a,b)
# '''
#
# f = h5py.File(output_file)
# tile_3_0 = cht.get_data(f, 3, 0)
#
# assert(sum(tile_3_0) - sum(prev_tile_3_0) < 0.0001)


testdir = op.realpath(op.dirname(__file__))
Expand Down Expand Up @@ -186,13 +187,9 @@ def test_clodius_aggregate_bedpe():
assert(result.exit_code == 0)

tiles = cdt.get_2d_tiles(output_file, 0, 0, 0, numx=1, numy=1)
# print("tiles:", tiles)

assert('\n' not in tiles[(0, 0)][0]['fields'][2])

#import json
# json.dumps(tiles)


testdir = op.realpath(op.dirname(__file__))

Expand Down Expand Up @@ -221,7 +218,8 @@ def test_clodius_aggregate_bedgraph1():
# print("result.output", result.output)

f = h5py.File('/tmp/dm3_values.hitile')
max_zoom = f['meta'].attrs['max-zoom']
# max_zoom = f['meta'].attrs['max-zoom']
# TODO: Make assertions about result
values = f['values_0']

import numpy as np
Expand Down Expand Up @@ -264,7 +262,8 @@ def test_clodius_aggregate_bedgraph1():
# print('output:', result.output, result)

f = h5py.File('/tmp/test3chroms_values.hitile')
max_zoom = f['meta'].attrs['max-zoom']
# f['meta'].attrs['max-zoom']
# TODO: Make assertions about result

# print('max_zoom:', max_zoom)
# print("len", len(f['values_0']))
Expand Down
5 changes: 2 additions & 3 deletions test/fpark_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import clodius.fpark as fp


Expand All @@ -14,7 +12,8 @@ def test_group_by_key():
a = fp.FakeSparkContext.parallelize(
[(1, 2), (1, 3), (1, 4), (2, 5), (2, 6)])

b = a.groupByKey()
a.groupByKey()
# TODO: Make assertions about result


def test_textFile():
Expand Down
7 changes: 5 additions & 2 deletions test/mrmatrix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def test_padding(self):
'1': {
'values': np.array([[1.0, 2], [3, 4]])
# It's important that there is a float value:
# If there isn't, np.nan will be converted to a large negative integer.
# If there isn't, np.nan will be converted
# to a large negative integer.
}
}
})
Expand All @@ -91,7 +92,9 @@ def test_bins(self):
tileset = MockHdf5({
'resolutions': {
'1': {
'values': np.array([[float(x) for x in range(500)] for y in range(500)])
'values': np.array(
[[float(x) for x in range(500)] for y in range(500)]
)
}
}
})
Expand Down
Loading

0 comments on commit e6f6f9d

Please sign in to comment.