Ejemplo n.º 1
0
def test_many_roots_same_filename():
    roots = ['tests/test_data/many_roots/dir' + str(index) for index in [1, 4]]
    many_roots = Bazefetcher(roots)
    with pytest.raises(ValueError) as excinfo:
        many_roots("root_tag", t1_1, t1_5)
    assert ('files [\'root_tag_2030-01-03T00.00.00+00.00_2030-01-04T00.00.00'
            '+00.00.json.gz\'] are not unique' in str(excinfo.value))
Ejemplo n.º 2
0
def test_many_roots():
    baze_and_authored = Bazefetcher(
        paths=['tests/test_data/authored', 'tests/test_data/baze'])

    sin_b = baze_and_authored('Sin-T60s-SR01hz', t1_2, t1_4)
    assert len(sin_b) == 17280

    i04_status_b = authored('installation-04-status', t12_31_23, t1_5_1)
    assert len(i04_status_b) == 5
Ejemplo n.º 3
0
def test_many_roots_same_tag():
    roots = [
        'tests/test_data/many_roots/dir' + str(index) for index in [3, 1, 2]
    ]
    many_roots = Bazefetcher(roots)
    tag = "root_tag"
    root = many_roots(tag, t1_1, t1_5)
    assert len(root) == 7

    root = many_roots(tag, t1_3, t1_3_21)
    assert len(root) == 1

    root = many_roots(tag, t1_3, t1_3_21, snap='right')
    assert len(root) == 2
Ejemplo n.º 4
0
def test_remote_root():
    with mock_remote_ssh():
        remote_baze = Bazefetcher('127.0.0.1:tests/test_data/baze')

        sin_b = remote_baze('Sin-T60s-SR01hz', t1_2, t1_4)
        tan_b = remote_baze('Tan-T60s-SR01hz', t1_2, t1_4)
        assert len(sin_b) == len(tan_b) == 17280  # 2 days
        pd.testing.assert_series_equal(sin_b,
                                       sin(t1_2, t1_4),
                                       check_freq=False)
        pd.testing.assert_series_equal(tan_b,
                                       tan(t1_2, t1_4),
                                       check_freq=False)
        assert sin_b.index[0] == t1_2
        assert sin_b.index[-1] < t1_4
        assert (t1_4 -
                sin_b.index[-1]).to_pytimedelta() < timedelta(seconds=20)
Ejemplo n.º 5
0
#!/usr/bin/env python3
from camille.source import Bazefetcher, TagNotFoundError
from camille.source.bazefetcher import RemoteIO
from camille.source.bazefetcher import _get_files_between_start_and_end
from datetime import datetime, timedelta
from math import pi
from pytz import utc
from unittest import mock
import contextlib
import mockssh
import numpy as np
import pandas as pd
import pytest

authored = Bazefetcher('tests/test_data/authored')
baze = Bazefetcher('tests/test_data/baze')
non_standard = Bazefetcher('tests/test_data/non_standard_names')


@contextlib.contextmanager
def mock_remote_ssh():
    with contextlib.ExitStack() as exit_stack:
        users = {'ssh-user': '******'}
        server = exit_stack.enter_context(mockssh.Server(users))
        client = exit_stack.enter_context(server.client('ssh-user'))

        connect_mock = exit_stack.enter_context(
            mock.patch(
                'camille.source.bazefetcher.RemoteIO._create_connection'))
        connect_mock.return_value = client
Ejemplo n.º 6
0
#!/usr/bin/env python3
from camille.source import Bazefetcher
from datetime import datetime, timedelta
from math import pi
from pytz import utc
import pytest
import pandas as pd
import numpy as np

baze = Bazefetcher('tests/test_data/baze')
sin_tag = 'Sin-T60s-SR01hz'
cos_tag = 'Cos-T60s-SR01hz'

t1 = datetime(2030, 1, 1, tzinfo=utc)
t2 = datetime(2030, 1, 2, tzinfo=utc)
t3 = datetime(2030, 1, 3, tzinfo=utc)
t4 = datetime(2030, 1, 4, tzinfo=utc)
eps = timedelta(microseconds=1)

invalid_date = datetime(2030, 1, 1, 10, tzinfo=utc)
invalid_interval = timedelta(1.5)

trng = pd.date_range(t1, t4, freq="10S", name='time', closed='left')
t = trng.map(lambda t: (t - t1).total_seconds())

_sin = pd.Series(np.sin(t * pi / 6), index=trng, name='value')
#sin data are spaced per every 10 seconds
day_data_length = 24 * 60 * 6
_cos = pd.Series(np.cos(t * pi / 6), index=trng, name='value')

Ejemplo n.º 7
0
def test_no_directories():
    with pytest.raises(ValueError) as excinfo:
        Bazefetcher('tests/test_data/baze/perling')
    assert ('no file in [\'tests/test_data/baze/perling\'] is a directory'
            in str(excinfo.value))