<s> import os <EOL> import shutil <EOL> import numpy as np <EOL> import pandas as pd <EOL> import pytest <EOL> from . . import misc <EOL> class _FakeTable ( object ) : <EOL> def __init__ ( self , name , columns ) : <EOL> self . name = name <EOL> self . columns = columns <EOL> @ pytest . fixture <EOL> def fta ( ) : <EOL> return _FakeTable ( '<STR_LIT:a>' , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ pytest . fixture <EOL> def ftb ( ) : <EOL> return _FakeTable ( '<STR_LIT:b>' , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ pytest . fixture <EOL> def clean_fake_data_home ( request ) : <EOL> def fin ( ) : <EOL> if os . path . isdir ( '<STR_LIT>' ) : <EOL> shutil . rmtree ( '<STR_LIT>' ) <EOL> request . addfinalizer ( fin ) <EOL> def test_column_map_raises ( fta , ftb ) : <EOL> with pytest . raises ( RuntimeError ) : <EOL> misc . column_map ( [ fta , ftb ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_column_map_none ( fta , ftb ) : <EOL> assert misc . column_map ( [ fta , ftb ] , None ) == { '<STR_LIT:a>' : None , '<STR_LIT:b>' : None } <EOL> def test_column_map ( fta , ftb ) : <EOL> assert misc . column_map ( [ fta , ftb ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) == { '<STR_LIT:a>' : [ '<STR_LIT>' ] , '<STR_LIT:b>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> assert misc . column_map ( [ fta , ftb ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) == { '<STR_LIT:a>' : [ ] , '<STR_LIT:b>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> def test_dirs ( clean_fake_data_home ) : <EOL> misc . _mkifnotexists ( "<STR_LIT>" ) <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> misc . get_run_number ( ) <EOL> misc . get_run_number ( ) <EOL> misc . data_dir ( ) <EOL> misc . configs_dir ( ) <EOL> misc . models_dir ( ) <EOL> misc . charts_dir ( ) <EOL> misc . maps_dir ( ) <EOL> misc . simulations_dir ( ) <EOL> misc . reports_dir ( ) <EOL> misc . runs_dir ( ) <EOL> misc . config ( "<STR_LIT:test>" ) <EOL> @ pytest . fixture <EOL> def range_df ( ) : <EOL> df = pd . DataFrame ( { '<STR_LIT>' : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] } ) <EOL> df = df . set_index ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return df <EOL> @ pytest . fixture <EOL> def range_series ( ) : <EOL> return pd . Series ( [ <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> def test_compute_range ( range_df , range_series ) : <EOL> assert misc . compute_range ( range_df , range_series , "<STR_LIT>" , <NUM_LIT> ) . loc [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> def test_reindex ( ) : <EOL> s = pd . Series ( [ <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:3> ] ) <EOL> s2 = pd . Series ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) <EOL> assert list ( misc . reindex ( s , s2 ) . values ) == [ <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ] <EOL> def test_naics ( ) : <EOL> assert misc . naicsname ( <NUM_LIT> ) == "<STR_LIT>" <EOL> def test_signif ( ) : <EOL> assert misc . signif ( <NUM_LIT> ) == '<STR_LIT>' <EOL> assert misc . signif ( <NUM_LIT> ) == '<STR_LIT>' <EOL> assert misc . signif ( <NUM_LIT> ) == '<STR_LIT:*>' <EOL> assert misc . signif ( <NUM_LIT> ) == '<STR_LIT:.>' <EOL> assert misc . signif ( <NUM_LIT:1.0> ) == '<STR_LIT>' <EOL> @ pytest . fixture <EOL> def simple_dev_inputs ( ) : <EOL> return pd . DataFrame ( <EOL> { '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:15> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT:12> , <NUM_LIT:10> , <NUM_LIT:10> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] , <EOL> '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] } , <EOL> index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) <EOL> def test_misc_dffunctions ( simple_dev_inputs ) : <EOL> misc . df64bitto32bit ( simple_dev_inputs ) <EOL> misc . pandasdfsummarytojson ( simple_dev_inputs [ [ '<STR_LIT>' , '<STR_LIT>' ] ] ) <EOL> misc . numpymat2df ( np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) ) <EOL> def test_column_list ( fta , ftb ) : <EOL> assert misc . column_list ( [ fta , ftb ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:c>' ] ) == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] </s>
