Пример #1
0
 def test_deduplicate(self):
     assert 'archiver' == os.path.basename(self.archiver_path)
     assert os.path.exists(self.archiver_path)
     contents = ytc.source_path("tools/archiver/tests/directory")
     ytc.execute(command=[
         self.archiver_path,
         "--output",
         "result_dedup",
         "--recursive",
         "--deduplicate",
         "--plain",
         contents,
     ])
     ytc.execute(command=[
         self.archiver_path,
         "--output",
         "result_no_dedup",
         "--recursive",
         "--plain",
         contents,
     ])
     with open('result_dedup',
               'rb') as f_dedup, open('result_no_dedup',
                                      'rb') as f_no_dedup:
         archive_dedup = f_dedup.read()
         archive_no_dedup = f_no_dedup.read()
     assert len(archive_dedup) == 58
     assert len(archive_no_dedup) == 75
Пример #2
0
 def test_recursive(self):
     assert 'archiver' == os.path.basename(self.archiver_path)
     assert os.path.exists(self.archiver_path)
     contents = ytc.source_path("tools/archiver/tests/directory")
     ytc.execute(command=[
         self.archiver_path,
         "--output",
         "archive",
         "--recursive",
         contents,
     ])
     with open('result', 'w') as archive_list:
         ytc.execute(
             command=[
                 self.archiver_path,
                 "--list",
                 "archive",
             ],
             stdout=archive_list,
             stderr=None,
         )
     archive_list = sorted(open('result').read().strip().split('\n'))
     assert len(archive_list) == 3
     assert archive_list[0] == 'file1'
     assert archive_list[1] == 'file2'
     assert archive_list[2] == 'file3'
Пример #3
0
def _get_input_replace_map():
    # order matters - source_path is build_path's subdir
    d = collections.OrderedDict()
    d[ytc.source_path()] = get_yt_sandbox_path('env/source_path')
    d[ytc.data_path()] = get_yt_sandbox_path('env/data_path')
    # yatest.common.binary_path() based on build_path()
    d[ytc.build_path()] = get_yt_sandbox_path('env/build_path')
    return d
Пример #4
0
def _get_input_replace_map():
    tmpdir = ytc.misc.first(os.environ.get(var) for var in ['TMPDIR', 'TEMP', 'TMP']) or '/tmp'
    # order matters - source_path is build_path's subdir
    d = collections.OrderedDict()
    d[ytc.source_path()] = 'env/source_path'
    d[ytc.data_path()] = 'env/data_path'
    # yatest.common.binary_path() based on build_path()
    d[ytc.build_path()] = 'env/build_path'
    d[tmpdir] = 'env/tempdir'
    return d
Пример #5
0
def pytest_runtest_setup(item):
    # Go to arcadia source route to access data files.
    import yatest.common as yc
    os.chdir(yc.source_path(''))

    if LooseVersion(pytest.__version__) >= LooseVersion("3.6.0"):
        mark = item.get_closest_marker("xslow")
    else:
        mark = item.get_marker("xslow")
    if mark is not None:
        try:
            v = int(os.environ.get('SCIPY_XSLOW', '0'))
        except ValueError:
            v = False
        if not v:
            pytest.skip(
                "very slow test; set environment variable SCIPY_XSLOW=1 to run it"
            )
Пример #6
0
from threading import Event
import os
import pytest as pytest

from yandextank.aggregator import TankAggregator
from yandextank.common.util import FileMultiReader
from yandextank.plugins.Phantom.reader import PhantomReader
try:
    from yatest import common
    PATH = common.source_path('load/projects/yandex-tank/yandextank/aggregator/tests/')
except ImportError:
    PATH = 'yandextank/aggregator/tests/'


class PhantomMock(object):
    def __init__(self, phout):
        self.phout_filename = phout
        self.reader = None
        self.finished = Event()

    def get_reader(self):
        if self.reader is None:
            self.reader = PhantomReader(FileMultiReader(self.phout_filename, self.finished).get_file())
        return self.reader

    def get_stats_reader(self):
        return (i for i in [])

    def end_test(self, retcode):
        return retcode
Пример #7
0
import io
import os
import threading

import pytest

from yandextank.common.util import read_resource
from yandextank.common.interfaces import TankInfo
from yandextank.core import TankCore
from yandextank.stepper import Stepper
from yandextank.stepper.load_plan import create, Const, Line, Composite, Stairway, StepFactory
from yandextank.stepper.util import take

try:
    from yatest import common
    PATH = common.source_path('load/projects/yandex-tank')
except ImportError:
    PATH = os.path.dirname(__file__)


class TestLine(object):
    def test_get_rps_list(self):
        lp = create(["line(1, 100, 10s)"])
        rps_list = lp.get_rps_list()
        assert len(rps_list) == 11
        assert rps_list[-1][0] == 100


@pytest.mark.parametrize("rps, duration, rps_list", [(100, 3000, [(100, 3)]),
                                                     (0, 3000, [(0, 3)]),
                                                     (100, 0, [(100, 0)])])
Пример #8
0
import ConfigParser
import os

import yaml
import pytest

from yandextank.config_converter.converter import convert_ini, parse_package_name, parse_sections, combine_sections, \
    convert_single_option, OptionsConflict
from yandextank.core.consoleworker import load_core_base_cfg, cfg_folder_loader, load_cfg
from yandextank.validator.validator import TankConfig
try:
    from yatest import common
    PATH = common.source_path(
        'load/projects/netort/netort/data_manager/metrics/tests/')
except ImportError:
    PATH = 'netort/data_manager/metrics/tests/'


@pytest.mark.parametrize('ini_file, expected', [
    ('test_config1.ini', {
        'phantom': 'Phantom',
        'telegraf': 'Telegraf',
        'meta': 'DataUploader'
    }),
    ('test_config2.ini', {
        'phantom': 'Phantom',
        'telegraf': 'Telegraf',
        'phantom-1': 'Phantom',
        'meta': 'DataUploader',
        'autostop': 'Autostop'
    }),
Пример #9
0
import pandas as pd
import pytest
import json
import os

from numpy.testing import assert_array_equal

from yandextank.plugins.NeUploader.plugin import Plugin
try:
    from yatest import common
    PATH = common.source_path(
        'load/projects/yandex-tank/yandextank/plugins/NeUploader/tests')
except ImportError:
    PATH = os.path.dirname(__file__)


class TestMonitoringData(object):
    @pytest.mark.parametrize('mon_data, length', [
        (os.path.join(PATH, 'monitoring_data/monitoring1.json'), 54),
    ])
    def test_df_num_and_cols(self, mon_data, length):
        with open(mon_data) as f:
            jsondata = json.load(f)
            dfs = Plugin.monitoring_data_to_dfs(jsondata)
        assert len(dfs) == length
        assert all(
            [list(df.columns) == ['ts', 'value'] for df in dfs.values()])

    @pytest.mark.parametrize('mon_data, names', [
        (os.path.join(PATH, 'monitoring_data/monitoring1.json'), ()),
    ])
Пример #10
0
import logging
import os
import threading

import pytest
import sys

import shutil
import yaml

from yandextank.core import TankCore
from yandextank.core.tankworker import parse_options, TankInfo

try:
    from yatest import common
    PATH = common.source_path(
        'load/projects/yandex-tank/yandextank/core/tests')
    TMPDIR = os.path.join(os.getcwd(), 'artifacts_dir')
except ImportError:
    PATH = os.path.dirname(__file__)
    TMPDIR = './'

logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler(sys.stdout)
fmt = logging.Formatter(
    "%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)d\t%(message)s"
)
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(fmt)
logger.addHandler(console_handler)
Пример #11
0
import threading
import os

from yandextank.core.tankcore import TankCore
from yandextank.core.tankworker import TankInfo
from yandextank.plugins.Telegraf import Plugin as TelegrafPlugin
try:
    from yatest import common
    PATH = common.source_path(
        'load/projects/yandex-tank/yandextank/plugins/Telegraf/tests')
except ImportError:
    PATH = os.path.dirname(__file__)


class TestTelegrafPlugin(object):
    def test_plugin_configuration(self):
        """ testing telegraf plugin configuration """
        cfg = {
            'core': {},
            'telegraf': {
                'package': 'yandextank.plugins.Telegraf',
                'enabled': True,
                'config': os.path.join(PATH, 'telegraf_mon.xml')
            }
        }
        core = TankCore(cfg, threading.Event(), TankInfo({}))
        telegraf_plugin = core.get_plugin_of_type(TelegrafPlugin)
        telegraf_plugin.configure()
        assert telegraf_plugin.detected_conf == 'telegraf'

    def test_legacy_plugin_configuration(self):
Пример #12
0
from threading import Event
import os
import pandas as pd

from yandextank.common.util import FileMultiReader
from yandextank.plugins.Phantom.reader import PhantomReader, PhantomStatsReader, string_to_df_microsec
try:
    from yatest import common
    PATH = common.source_path('load/projects/yandex-tank/yandextank/plugins/Phantom/tests')
except ImportError:
    PATH = os.path.dirname(__file__)


class TestPhantomReader(object):
    def setup_class(self):
        stop = Event()
        self.multireader = FileMultiReader(os.path.join(PATH, 'phout.dat'), stop)
        stop.set()

    def teardown_class(self):
        self.multireader.close()

    def test_read_all(self):
        reader = PhantomReader(
            self.multireader.get_file(), cache_size=1024)
        df = pd.DataFrame()
        for chunk in reader:
            df = df.append(chunk)
        assert (len(df) == 200)
        assert (df['interval_real'].mean() == 11000714.0)