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

Unit testing framework #26

Merged
merged 8 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/sampleFile.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
favoriteColor,name
blue,phil
green,tom
4 changes: 4 additions & 0 deletions tests/sampleMeta.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,mexico,serbia,favoriteMeat,favoriteFruit
1,quien,ко,bacon,orange
2,que,Шта,bacon,banana
3,donde,где,,
Empty file added tests/unit/__init__.py
Empty file.
61 changes: 61 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pytest
import sys
import logging
import pandas
import synapseclient


SAMPLE_FILE = "../sampleFile.csv"
SAMPLE_META = "../sampleMeta.csv"


@pytest.fixture(scope='session')
def syn():
syn = synapseclient.login()
return syn


@pytest.fixture(scope='session')
def sampleEntities():
data = pandas.read_csv(SAMPLE_FILE, header=0, index_col=None)
meta = pandas.read_csv(SAMPLE_META, header=0, index_col=None)
return {'data': data, 'meta': meta}


@pytest.fixture(scope='session')
def entities(syn, sampleEntities):
import uuid # random project name
project = synapseclient.Project(str(uuid.uuid4()))
project = syn.store(project)
# store sample files
_file = synapseclient.File(path=SAMPLE_FILE, name='file1.csv',
parent=project)
_file = syn.store(_file)
_file2 = synapseclient.File(path=SAMPLE_FILE, name='file2.csv',
parent=project)
_file2 = syn.store(_file2)
_file3 = synapseclient.File(path=SAMPLE_FILE, name='file3.csv.gz',
parent=project)
_file3 = syn.store(_file3)
# store a sample metadata file
meta = synapseclient.File(path=SAMPLE_META, name='meta', parent=project)
meta = syn.store(meta)
# store a sample table (same values as sample file)
df = sampleEntities['data']
cols = synapseclient.as_table_columns(df)
schema = synapseclient.Schema(name="table", columns=cols,
parent=project)
schema = syn.store(schema)
table = syn.store(synapseclient.Table(schema, df))
# store a sample file view
entity_view = synapseclient.EntityViewSchema(
name='entity_view',
parent=project,
scopes=[project])
entity_view = syn.store(entity_view)
ents = {'files': [_file, _file2, _file3],
'meta': meta,
'schema': schema,
'entity_view': entity_view}
yield ents
syn.delete(project)
Empty file added tests/unit/test_Pipeline.py
Empty file.
Empty file added tests/unit/test_schema.py
Empty file.
42 changes: 42 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import annotator
import pandas


def test_setUp(syn, sampleEntities, entities):
""" Set up working environment on Synapse,
passes if set-up is successful
"""
assert True


def test_synread_csv(syn, sampleEntities, entities):
df = annotator.utils.synread(syn, entities['files'][0].id, sortCols=False)
pandas.testing.assert_frame_equal(df, sampleEntities['data'],
check_like=True)


def test_synread_table(syn, sampleEntities, entities):
df = annotator.utils.synread(syn, entities['schema'].id, sortCols=False)
pandas.testing.assert_frame_equal(
df.reset_index(drop=True),
sampleEntities['data'],
check_like=True)


def test_synread_entity_view(syn, sampleEntities, entities):
df = annotator.utils.synread(
syn,
entities['entity_view'].id,
sortCols=False)
assert isinstance(df, pandas.DataFrame)


def test_synread_list_csv(syn, sampleEntities, entities):
listOfDataFrames = annotator.utils.synread(
syn,
[f['id'] for f in entities['files']],
sortCols=False)
pandas.testing.assert_frame_equal(
listOfDataFrames[0],
sampleEntities['data'],
check_like=True)