-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: speed up tests using fixture (#93)
Subset of HTS007 with single cell line for some tests, to increase speed. Also, replace use of pkg_resources with importlib.
- Loading branch information
Showing
6 changed files
with
24 additions
and
57 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import pkg_resources | ||
import importlib.resources | ||
import os | ||
import thunor | ||
|
||
|
||
def get_thunor_test_file(filename): | ||
try: | ||
return pkg_resources.resource_stream('thunor', filename) | ||
return importlib.resources.files('thunor').joinpath(filename) | ||
except OSError: | ||
# Provide a method to load from filesystem within Docker container | ||
fn = os.path.join('thunor/thunor', filename) | ||
fn = os.path.join('thunorcore/thunor', filename) | ||
if os.path.exists(fn) and os.path.isfile(fn): | ||
return open(fn, 'rb') | ||
return fn | ||
|
||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
from django.test import TestCase | ||
from django.core.files import File | ||
from thunorweb.plate_parsers import PlateFileParser | ||
from thunorweb.models import HTSDataset, CellLine, Drug | ||
from thunorweb.tests import get_thunor_test_file | ||
from django.contrib.auth import get_user_model | ||
from django.urls import reverse | ||
import json | ||
|
@@ -12,24 +9,15 @@ | |
|
||
|
||
class TestPlateMapper(TestCase): | ||
fixtures = ['testing-hts007-hcc1143.json'] | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
UserModel = get_user_model() | ||
cls.user = UserModel.objects.create_user( | ||
email='[email protected]', password='test') | ||
|
||
cls.d = HTSDataset.objects.create(owner=cls.user, name='test') | ||
hts007 = get_thunor_test_file('testdata/hts007.h5') | ||
try: | ||
f = File(hts007, name='hts007.h5') | ||
pfp = PlateFileParser(f, dataset=cls.d) | ||
results = pfp.parse_all() | ||
finally: | ||
hts007.close() | ||
|
||
assert len(results) == 1 | ||
assert results[0]['success'] | ||
assert results[0]['file_format'] == 'HDF5' | ||
cls.user = UserModel.objects.get( | ||
email='[email protected]') | ||
|
||
cls.d = HTSDataset.objects.get(owner=cls.user, name='test') | ||
|
||
def test_load_save_plate(self): | ||
plate_id = self.d.plate_set.first().id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,31 +11,20 @@ | |
|
||
|
||
class TestPlots(TestCase): | ||
fixtures = ['testing-hts007-hcc1143.json'] | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
UserModel = get_user_model() | ||
cls.user = UserModel.objects.create_user( | ||
email='[email protected]', password='test') | ||
cls.user = UserModel.objects.get( | ||
email='[email protected]') | ||
cls.other_user = UserModel.objects.create_user( | ||
email='[email protected]', password='test') | ||
|
||
c = Client() | ||
c.force_login(cls.user) | ||
|
||
resp = c.post(reverse('thunorweb:ajax_create_dataset'), | ||
{'name': 'test'}) | ||
resp_json = json.loads(resp.content) | ||
dataset_id = resp_json['id'] | ||
cls.d = HTSDataset.objects.get(pk=dataset_id) | ||
|
||
hts007 = get_thunor_test_file('testdata/hts007.h5') | ||
try: | ||
response = c.post(reverse('thunorweb:ajax_upload_platefiles'), | ||
{'file_field[]': hts007, 'dataset_id': | ||
cls.d.id}) | ||
finally: | ||
hts007.close() | ||
|
||
assert response.status_code == HTTP_OK | ||
cls.d = HTSDataset.objects.get() | ||
|
||
# Create some cell line and drug tags | ||
entities_per_tag = 3 | ||
|
@@ -58,7 +47,7 @@ def setUpTestData(cls): | |
for tag_num in range(num_tags): | ||
idx = range(tag_num * entities_per_tag, | ||
tag_num * (entities_per_tag + 1)) | ||
cltags[tag_num].cell_lines.set([cell_lines[i] for i in idx]) | ||
cltags[tag_num].cell_lines.set([cell_lines[0]]) | ||
drtags[tag_num].drugs.set([drugs[i] for i in idx]) | ||
|
||
# Get the dataset groupings | ||
|