<commit_before>#!/usr/bin/env python
# encoding: utf-8
#
# conftest.py
#
# Created by <NAME> on 20 Mar 2017.


from collections import OrderedDict
import itertools
import os

import pytest

from marvin import config, marvindb
from marvin.api.api import Interaction
from marvin.tools.cube import Cube
from marvin.tools.modelcube import ModelCube
from marvin.tools.maps import Maps
from marvin.tools.query import Query
from marvin.tools.maps import _get_bintemps, __BINTYPES_MPL4__, __TEMPLATES_KIN_MPL4__
from sdss_access.path import Path
import yaml


# PYTEST MODIFIERS
# -----------------
def pytest_addoption(parser):
    """Add new options"""
    # run slow tests
    parser.addoption('--runslow', action='store_true', default=False, help='Run slow tests.')
    # control releases run
    #parser.addoption('--release', type=str, default=None, help='Run a certain release only')
    parser.addoption('--travis-only', action='store_true', default=False, help='Run a Travis only subset')


def pytest_runtest_setup(item):
    """Skip slow tests."""
    if 'slow' in item.keywords and not item.config.getoption('--runslow'):
        pytest.skip('Requires --runslow option to run.')


# def pytest_configure(config):
#     ''' Runs during configuration of conftest.  Checks and sets a global instance for a
#         SpecificRelease based on the pytest command line input of --release
#     '''
#     opt = config.getoption('--release')
#     global sprelease
#     sprelease = SpecificRelease(opt)

def pytest_configure(config):
    ''' Runs during configuration of conftest.  Checks and sets a global instance for a
        TravisSubset based on the pytest command line input of --travis-only
    '''
    option = config.getoption('--travis-only')
    global travis
    if option:
        print('option')
        travis = TravisSubset()

# specific release instance
travis = None


class TravisSubset(object):
    def __init__(self):
        self.new_gals = ['8485-1901']
        self.new_releases = ['MPL-5']
        self.new_bintypes = ['SPX'] #['SPX', 'VOR10', 'NONE', 'STON']
        self.new_templates = ['GAU-MILESHC', 'MILES-THIN']
        self.new_dbs = ['nodb']
        self.new_origins = ['file', 'api']
        self.new_modes = ['local', 'remote']

# class SpecificRelease(object):
#     def __init__(self, release):
#         self.chosen_release = release
#         self.set_new_releases()

#     def set_new_releases(self):
#         global releases
#         if self.chosen_release is None:
#             new = releases
#         elif self.chosen_release == 'latest':
#             new = max([r for r in releases if 'MPL' in r])
#         elif 'MPL' in self.chosen_release or 'DR' in self.chosen_release:
#             newr = [r for r in releases if r == self.chosen_release]
#             new = releases if not newr else newr
#         self.new_releases = new

#     @pytest.fixture()
#     def skiprelease(self):
#         if releases != self.new_releases:
#             pass

# Global Parameters for FIXTURES
# ------------------------------
releases = ['MPL-5', 'MPL-4']           # to loop over releases (see release fixture)


def populate_bintypes_templates(releases):
    ''' Generates bintype and template dictionaries for each release '''
    bintypes = OrderedDict((release, []) for release in releases)
    templates = OrderedDict((release, []) for release in releases)
    for release in releases:
        __, dapver = config.lookUpVersions(release)
        bintemps = _get_bintemps(dapver)
        for bintemp in bintemps:
            bintype = bintemp.split('-')[0]
            template = '-'.join(bintemp.split('-')[1:])
            if bintype not in bintypes[release]:
                bintypes[release].append(bintype)
            if template not in templates[release]:
                templates[release].append(template)
    return bintypes, templates


bintypes, templates = populate_bintypes_templates(releases)

modes = ['local', 'remote', 'auto']     # to loop over modes (see mode fixture)
dbs = ['db', 'nodb']                    # to loop over dbs (see db fixture)
origins = ['file', 'db', 'api']         # to loop over data origins (see data_origin fixture)


# Galaxy and Query data is stored in a YAML file
galaxy_data = yaml.load(open(os.path.join(os.path.dirname(__file__), 'data/galaxy_test_data.dat')))
query_data = yaml.load(open(os.path.join(os.path.dirname(__file__), 'data/query_test_data.dat')))


@pytest.fixture(scope='session', params=releases)
def release(request):<commit_msg>adds TODO<commit_after>#!/usr/bin/env python
# encoding: utf-8
#
# conftest.py
#
# Created by <NAME> on 20 Mar 2017.


from collections import OrderedDict
import itertools
import os

import pytest

from marvin import config, marvindb
from marvin.api.api import Interaction
from marvin.tools.cube import Cube
from marvin.tools.modelcube import ModelCube
from marvin.tools.maps import Maps
from marvin.tools.query import Query
from marvin.tools.maps import _get_bintemps, __BINTYPES_MPL4__, __TEMPLATES_KIN_MPL4__
from sdss_access.path import Path
import yaml


# PYTEST MODIFIERS
# -----------------
def pytest_addoption(parser):
    """Add new options"""
    # run slow tests
    parser.addoption('--runslow', action='store_true', default=False, help='Run slow tests.')
    # control releases run
    #parser.addoption('--release', type=str, default=None, help='Run a certain release only')
    parser.addoption('--travis-only', action='store_true', default=False, help='Run a Travis only subset')


def pytest_runtest_setup(item):
    """Skip slow tests."""
    if 'slow' in item.keywords and not item.config.getoption('--runslow'):
        pytest.skip('Requires --runslow option to run.')


# def pytest_configure(config):
#     ''' Runs during configuration of conftest.  Checks and sets a global instance for a
#         SpecificRelease based on the pytest command line input of --release
#     '''
#     opt = config.getoption('--release')
#     global sprelease
#     sprelease = SpecificRelease(opt)

def pytest_configure(config):
    ''' Runs during configuration of conftest.  Checks and sets a global instance for a
        TravisSubset based on the pytest command line input of --travis-only
    '''
    option = config.getoption('--travis-only')
    global travis
    if option:
        print('option')
        travis = TravisSubset()

# specific release instance
travis = None


class TravisSubset(object):
    def __init__(self):
        self.new_gals = ['8485-1901']
        self.new_releases = ['MPL-5']
        self.new_bintypes = ['SPX'] #['SPX', 'VOR10', 'NONE', 'STON']
        self.new_templates = ['GAU-MILESHC', 'MILES-THIN']
        self.new_dbs = ['nodb']
        self.new_origins = ['file', 'api']
        self.new_modes = ['local', 'remote']

# class SpecificRelease(object):
#     def __init__(self, release):
#         self.chosen_release = release
#         self.set_new_releases()

#     def set_new_releases(self):
#         global releases
#         if self.chosen_release is None:
#             new = releases
#         elif self.chosen_release == 'latest':
#             new = max([r for r in releases if 'MPL' in r])
#         elif 'MPL' in self.chosen_release or 'DR' in self.chosen_release:
#             newr = [r for r in releases if r == self.chosen_release]
#             new = releases if not newr else newr
#         self.new_releases = new

#     @pytest.fixture()
#     def skiprelease(self):
#         if releases != self.new_releases:
#             pass

# Global Parameters for FIXTURES
# ------------------------------
releases = ['MPL-5', 'MPL-4']           # to loop over releases (see release fixture)


def populate_bintypes_templates(releases):
    ''' Generates bintype and template dictionaries for each release '''
    bintypes = OrderedDict((release, []) for release in releases)
    templates = OrderedDict((release, []) for release in releases)
    for release in releases:
        __, dapver = config.lookUpVersions(release)
        bintemps = _get_bintemps(dapver)
        for bintemp in bintemps:
            bintype = bintemp.split('-')[0]
            template = '-'.join(bintemp.split('-')[1:])
            if bintype not in bintypes[release]:
                bintypes[release].append(bintype)
            if template not in templates[release]:
                templates[release].append(template)
    return bintypes, templates


bintypes, templates = populate_bintypes_templates(releases)

# TODO reduce modes to only local and remote
modes = ['local', 'remote', 'auto']     # to loop over modes (see mode fixture)
dbs = ['db', 'nodb']                    # to loop over dbs (see db fixture)
origins = ['file', 'db', 'api']         # to loop over data origins (see data_origin fixture)


# Galaxy and Query data is stored in a YAML file
galaxy_data = yaml.load(open(os.path.join(os.path.dirname(__file__), 'data/galaxy_test_data.dat')))
query_data = yaml.load(open(os.path.join(os.path.dirname(__file__), 'data/query_test_data.dat')))


@pytest.fixture(scope='session', params=releases)
def release(request):
{'fraction_non_alphanumeric': 0.12660590754364776, 'fraction_numerical': 0.005270670912484902, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6415315', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2790, 'n_words': 794}