<s> import pytest <EOL> pytest . importorskip ( '<STR_LIT>' ) <EOL> from functools import partial <EOL> from toolz import first <EOL> from sqlalchemy . exc import OperationalError <EOL> from odo import into , drop <EOL> from blaze import data as bz_data <EOL> from blaze import create_index <EOL> @ pytest . fixture <EOL> def sql ( ) : <EOL> data = [ ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:10> , <NUM_LIT:20> ) , ( <NUM_LIT:100> , <NUM_LIT:200> ) ] <EOL> sql = bz_data ( <EOL> '<STR_LIT>' , <EOL> dshape = '<STR_LIT>' , <EOL> ) <EOL> into ( sql , data ) <EOL> return sql <EOL> def test_column ( sql ) : <EOL> t = bz_data ( sql ) <EOL> r = list ( t [ '<STR_LIT:x>' ] ) <EOL> assert r == [ <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:100> ] <EOL> assert list ( t [ [ '<STR_LIT:x>' ] ] ) == [ ( <NUM_LIT:1> , ) , ( <NUM_LIT:10> , ) , ( <NUM_LIT:100> , ) ] <EOL> assert int ( t . count ( ) ) == <NUM_LIT:3> <EOL> def test_drop ( sql ) : <EOL> sql = sql . data <EOL> assert sql . exists ( sql . bind ) <EOL> drop ( sql ) <EOL> assert not sql . exists ( sql . bind ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , ( <EOL> '<STR_LIT:x>' , [ '<STR_LIT:x>' ] , [ '<STR_LIT:y>' ] , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , ( '<STR_LIT:x>' , ) , ( '<STR_LIT:y>' , ) , ( '<STR_LIT:x>' , '<STR_LIT:y>' ) , <EOL> ) ) <EOL> def test_create_index ( sql , cols ) : <EOL> create_index ( sql , cols , name = '<STR_LIT>' ) <EOL> with pytest . raises ( OperationalError ) : <EOL> create_index ( sql , cols , name = '<STR_LIT>' ) <EOL> def test_create_index_fails ( sql ) : <EOL> with pytest . raises ( KeyError ) : <EOL> create_index ( sql , '<STR_LIT:z>' , name = '<STR_LIT>' ) <EOL> with pytest . raises ( ValueError ) : <EOL> create_index ( sql , '<STR_LIT:x>' ) <EOL> with pytest . raises ( ValueError ) : <EOL> create_index ( sql , '<STR_LIT:z>' ) <EOL> def test_create_index_unique ( sql ) : <EOL> create_index ( sql , '<STR_LIT:y>' , name = '<STR_LIT>' , unique = True ) <EOL> assert len ( sql . data . indexes ) == <NUM_LIT:1> <EOL> idx = first ( sql . data . indexes ) <EOL> assert idx . unique <EOL> assert idx . columns . y == sql . data . c . y <EOL> def test_composite_index ( sql ) : <EOL> create_index ( sql , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , name = '<STR_LIT>' ) <EOL> with pytest . raises ( OperationalError ) : <EOL> create_index ( sql , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , name = '<STR_LIT>' ) <EOL> def test_composite_index_fails ( sql ) : <EOL> with pytest . raises ( KeyError ) : <EOL> create_index ( sql , [ '<STR_LIT:z>' , '<STR_LIT>' ] , name = '<STR_LIT>' ) <EOL> def test_composite_index_fails_with_existing_columns ( sql ) : <EOL> with pytest . raises ( KeyError ) : <EOL> create_index ( sql , [ '<STR_LIT:x>' , '<STR_LIT:z>' , '<STR_LIT>' ] , name = '<STR_LIT>' ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , ( '<STR_LIT:x>' , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) ) <EOL> def test_ignore_existing ( sql , cols ) : <EOL> create_call = partial ( <EOL> create_index , <EOL> sql , <EOL> cols , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> create_call ( ) <EOL> with pytest . raises ( OperationalError ) : <EOL> create_call ( ignore_existing = False ) <EOL> create_call ( ignore_existing = True ) </s>
