Skip to content

Commit

Permalink
Merge pull request #126 from cta-observatory/move_resources_tests
Browse files Browse the repository at this point in the history
Move resources and tests out of the package
  • Loading branch information
maxnoe authored Dec 13, 2018
2 parents b160f17 + 0fdd463 commit 4dbecbc
Show file tree
Hide file tree
Showing 34 changed files with 65 additions and 183 deletions.
54 changes: 0 additions & 54 deletions eventio/tests/test_open_file.py

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def finalize_options(self):

setup(
name='eventio',
version='0.11.0',
version='0.12.0',
description='Python read-only implementation of the EventIO file format',
long_description=long_description,
url='https://github.com/fact-project/pyeventio',
Expand All @@ -64,7 +64,7 @@ def finalize_options(self):
cmdclass=cmdclass,

package_data={
'eventio': ['resources/*', '*.c'],
'eventio': ['*.c'],
'eventio.simtel': ['*.c'],
},
install_requires=[
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import eventio
import pkg_resources
from os import path

from pytest import approx, raises, importorskip


testfile = pkg_resources.resource_filename(
'eventio', path.join('resources', 'one_shower.dat')
)
testfile_reuse = pkg_resources.resource_filename(
'eventio', path.join('resources', '3_gammas_reuse_5.dat')
)
testfile_two_telescopes = pkg_resources.resource_filename(
'eventio', path.join('resources', 'two_telescopes.dat')
)
testfile_zstd = pkg_resources.resource_filename(
'eventio',
path.join('resources', 'run102_gamma_za20deg_azm0deg-paranal-sst.corsika.zst')
)
testfile = 'tests/resources/one_shower.dat'
testfile_reuse = 'tests/resources/3_gammas_reuse_5.dat'
testfile_two_telescopes = 'tests/resources/two_telescopes.dat'
testfile_zstd = 'tests/resources/run102_gamma_za20deg_azm0deg-paranal-sst.corsika.zst'


def test_file_open():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import eventio
import pkg_resources
from os import path

from pytest import approx

testfile = pkg_resources.resource_filename(
'eventio', path.join('resources', 'one_shower.dat')
)

prod4_simtel = pkg_resources.resource_filename(
'eventio', path.join('resources', 'gamma_20deg_0deg_run103___cta-prod4-sst-astri_desert-2150m-Paranal-sst-astri.simtel.gz')
)
testfile = 'tests/resources/one_shower.dat'
prod4_simtel = 'tests/resources/gamma_20deg_0deg_run103___cta-prod4-sst-astri_desert-2150m-Paranal-sst-astri.simtel.gz'


def test_photo_electrons():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
pyhessio = pytest.importorskip("pyhessio")

testfile = resource_filename('eventio', 'resources/gamma_test_large_truncated.simtel.gz')
testfile = 'tests/resources/gamma_test_large_truncated.simtel.gz'


def test_adc_samples():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pkg_resources import resource_filename
import pytest
from pytest import approx
import numpy as np
Expand All @@ -8,26 +7,17 @@
yield_n_subobjects,
)

prod2_file = resource_filename('eventio', 'resources/gamma_test.simtel.gz')
prod4b_sst1m_file = resource_filename(
'eventio',
'resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz'
)
prod4b_astri_file = resource_filename(
'eventio',
'resources/gamma_20deg_0deg_run103___cta-prod4-sst-astri_desert-2150m-Paranal-sst-astri.simtel.gz'
)
prod2_file = 'tests/resources/gamma_test.simtel.gz'
prod4b_sst1m_file = 'tests/resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz'
prod4b_astri_file = 'tests/resources/gamma_20deg_0deg_run103___cta-prod4-sst-astri_desert-2150m-Paranal-sst-astri.simtel.gz'

test_files = [
EventIOFile(path) for path in
[prod2_file, prod4b_astri_file, prod4b_sst1m_file]
]

expected_adc_samples_event1_tel_id_38 = np.load(
resource_filename(
'eventio',
'resources/gamma_test.simtel_event1_tel_id_38_adc_samples.npy'
)
'tests/resources/gamma_test.simtel_event1_tel_id_38_adc_samples.npy'
)


Expand Down Expand Up @@ -418,9 +408,7 @@ def test_2017():
def test_2020_3_objects():
from eventio.simtel.objects import MCShower

hessio_data = np.load(resource_filename(
'eventio', 'resources/gamma_test_mc_shower.npy'
))
hessio_data = np.load('tests/resources/gamma_test_mc_shower.npy')
with EventIOFile(prod2_file) as f:
for i, o in enumerate(yield_n_and_assert(f, MCShower, n=3)):
mc = parse_and_assert_consumption(o, limit=2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
import pkg_resources
import os

from pytest import importorskip

from eventio.simtel import SimTelFile

prod2_path = pkg_resources.resource_filename(
'eventio',
os.path.join(
'resources',
'gamma_test.simtel.gz')
)

prod3_path = pkg_resources.resource_filename(
'eventio',
os.path.join(
'resources',
'gamma_test_large_truncated.simtel.gz')
)

prod4_path = pkg_resources.resource_filename(
'eventio',
os.path.join(
'resources',
'gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz')
)
prod2_path = 'tests/resources/gamma_test.simtel.gz'
prod3_path = 'tests/resources/gamma_test_large_truncated.simtel.gz'
prod4_path = 'tests/resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz'

# using a zstd file ensures SimTelFile is not seeking back, when reading
# a file
prod4_zst_path = pkg_resources.resource_filename(
'eventio',
os.path.join(
'resources',
'gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.zst')
)
prod4_zst_path = 'tests/resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.zst'


test_paths = [prod2_path, prod3_path, prod4_path]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from eventio.exceptions import check_type, WrongType
from eventio import EventIOFile
from eventio.simtel import History, ArrayEvent, TelescopeEvent
from pkg_resources import resource_filename
import pytest


prod4b_sst1m_file = resource_filename(
'eventio',
'resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz'
)
prod4b_sst1m_file = 'tests/resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz'


def test_single():
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import gzip
import tempfile
import pkg_resources
import os
import pytest

testfile = pkg_resources.resource_filename(
'eventio', os.path.join('resources', 'one_shower.dat')
)
testfile_gz = pkg_resources.resource_filename(
'eventio', os.path.join('resources', 'one_shower.dat.gz')
)
testfile_zstd = pkg_resources.resource_filename(
'eventio',
os.path.join('resources', 'run102_gamma_za20deg_azm0deg-paranal-sst.corsika.zst')
)
testfile = 'tests/resources/one_shower.dat'
testfile_gz = 'tests/resources/one_shower.dat.gz'
testfile_zstd = 'tests/resources/run102_gamma_za20deg_azm0deg-paranal-sst.corsika.zst'


def test_is_gzip():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from eventio.search_utils import collect_toplevel_of_type
from pkg_resources import resource_filename


prod4b_sst1m_file = resource_filename(
'eventio',
'resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz'
)
prod4b_sst1m_file = 'tests/resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.gz'

titles = [
'Events, without weights (Ra, log10(E))',
Expand Down
6 changes: 1 addition & 5 deletions eventio/tests/test_objects.py → tests/test_objects.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import pkg_resources
import eventio
from os import path

testfile = pkg_resources.resource_filename(
'eventio', path.join('resources', 'one_shower.dat')
)
testfile = 'tests/resources/one_shower.dat'


def test_tell():
Expand Down
36 changes: 36 additions & 0 deletions tests/test_open_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import eventio
from os import path
import pkg_resources


def test_is_install_folder_a_directory():
dir_ = path.dirname(eventio.__file__)
assert path.isdir(dir_)


def test_can_open_file():
testfile = 'tests/resources/one_shower.dat'
eventio.EventIOFile(testfile)


def test_file_is_iterable():
testfile = 'tests/resources/one_shower.dat'
f = eventio.EventIOFile(testfile)
for event in f:
pass


def test_file_has_correct_types():
testfile = 'tests/resources/one_shower.dat'
f = eventio.EventIOFile(testfile)
types = [o.header.type for o in f]

assert types == [1200, 1212, 1201, 1202, 1203, 1204, 1209, 1210]


def test_types_gzipped():
testfile = 'tests/resources/one_shower.dat'
f = eventio.EventIOFile(testfile)
types = [o.header.type for o in f]

assert types == [1200, 1212, 1201, 1202, 1203, 1204, 1209, 1210]
28 changes: 4 additions & 24 deletions eventio/tests/test_scripts.py → tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
import pytest
import os
import pkg_resources
from pytest import importorskip
from eventio import EventIOFile
from eventio.search_utils import yield_all_objects_depth_first

prod2_path = pkg_resources.resource_filename(
'eventio',
os.path.join(
'resources',
'gamma_test.simtel.gz')
)

prod4b_astri_file = pkg_resources.resource_filename(
'eventio',
'resources/gamma_20deg_0deg_run103___cta-prod4-sst-astri_desert-2150m-Paranal-sst-astri.simtel.gz'
)

prod4b_corsika = pkg_resources.resource_filename(
'eventio',
'resources/run102_gamma_za20deg_azm0deg-paranal-sst.corsika.zst'
)


simple_corsika = pkg_resources.resource_filename(
'eventio',
'resources/one_shower.dat'
)
prod2_path = 'tests/resources/gamma_test.simtel.gz'
prod4b_astri_file = 'tests/resources/gamma_20deg_0deg_run103___cta-prod4-sst-astri_desert-2150m-Paranal-sst-astri.simtel.gz'
prod4b_corsika = 'tests/resources/run102_gamma_za20deg_azm0deg-paranal-sst.corsika.zst'
simple_corsika = 'tests/resources/one_shower.dat'


def test_reprs_prod2():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from pkg_resources import resource_filename


test_file = resource_filename('eventio', 'resources/gamma_test.simtel.gz')
test_file = 'tests/resources/gamma_test.simtel.gz'


def test_find_all_subobjects():
Expand Down
File renamed without changes.

0 comments on commit 4dbecbc

Please sign in to comment.