<commit_before>from datetime import timedelta
import itertools

import pytest

sa = pytest.importorskip('sqlalchemy')
pytest.importorskip('psycopg2')

import numpy as np
import pandas as pd

import pandas.util.testing as tm

from odo import odo, resource, drop, discover
from blaze import symbol, compute, concat, join, sin, cos, radians, atan2
from blaze import sqrt, transform, Data
from blaze.utils import example, normalize


names = ('tbl%d' % i for i in itertools.count())


@pytest.fixture
def url():
    return 'postgresql://postgres@localhost/test::%s'


@pytest.yield_fixture
def sql(url):
    try:
        t = resource(url % next(names), dshape='var * {A: string, B: int64}')
    except sa.exc.OperationalError as e:
        pytest.skip(str(e))
    else:
        t = odo([('a', 1), ('b', 2)], t)
        try:
            yield t
        finally:
            drop(t)


@pytest.yield_fixture(scope='module')
def nyc():
    try:
        t = odo(example('nyc.csv'),
                'postgresql://postgres@localhost/test::nyc')
    except sa.exc.OperationalError as e:
        pytest.skip(str(e))
    else:
        try:
            yield t
        finally:
            drop(t)


@pytest.yield_fixture
def sqla(url):
    try:
        t = resource(url % next(names), dshape='var * {A: ?string, B: ?int32}')
    except sa.exc.OperationalError as e:
        pytest.skip(str(e))
    else:
        t = odo([('a', 1), (None, 1), ('c', None)], t)
        try:
            yield t
        finally:
            drop(t)


@pytest.yield_fixture
def sqlb(url):
    try:
        t = resource(url % next(names), dshape='var * {A: string, B: int64}')
    except sa.exc.OperationalError as e:
        pytest.skip(str(e))
    else:
        t = odo([('a', 1), ('b', 2)], t)
        try:
            yield t
        finally:
            drop(t)
<commit_msg>Allow test_dist to work on pg installations without local permissions<commit_after>from datetime import timedelta
import itertools
import tempfile

import pytest

sa = pytest.importorskip('sqlalchemy')
pytest.importorskip('psycopg2')

import numpy as np
import pandas as pd

import pandas.util.testing as tm

from odo import odo, resource, drop, discover
from odo.utils import tmpfile
from blaze import symbol, compute, concat, join, sin, cos, radians, atan2
from blaze import sqrt, transform, Data
from blaze.utils import example, normalize


names = ('tbl%d' % i for i in itertools.count())


@pytest.fixture
def url():
    return 'postgresql://postgres@localhost/test::%s'


@pytest.yield_fixture
def sql(url):
    try:
        t = resource(url % next(names), dshape='var * {A: string, B: int64}')
    except sa.exc.OperationalError as e:
        pytest.skip(str(e))
    else:
        t = odo([('a', 1), ('b', 2)], t)
        try:
            yield t
        finally:
            drop(t)


@pytest.yield_fixture(scope='module')
def nyc():
    with open(example('nyc.csv'), 'rb') as f:
        raw = f.read()
        with tmpfile('.csv') as name:
            with open(name, 'wb') as g:
                g.write(raw)
            try:
                t = odo(name, 'postgresql://postgres@localhost/test::nyc')
            except sa.exc.OperationalError as e:
                pytest.skip(str(e))
            else:
                try:
                    yield t
                finally:
                    drop(t)


@pytest.yield_fixture
def sqla(url):
    try:
        t = resource(url % next(names), dshape='var * {A: ?string, B: ?int32}')
    except sa.exc.OperationalError as e:
        pytest.skip(str(e))
    else:
        t = odo([('a', 1), (None, 1), ('c', None)], t)
        try:
            yield t
        finally:
            drop(t)


@pytest.yield_fixture
def sqlb(url):
    try:
        t = resource(url % next(names), dshape='var * {A: string, B: int64}')
    except sa.exc.OperationalError as e:
        pytest.skip(str(e))
    else:
        t = odo([('a', 1), ('b', 2)], t)
        try:
            yield t
        finally:
            drop(t)

{'fraction_non_alphanumeric': 0.13579630554168748, 'fraction_numerical': 0.006989515726410384, 'mean_word_length': 2.2262479871175525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1076420', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1369, 'n_words': 374}