<s> import subprocess <EOL> from mock import patch , MagicMock <EOL> from unittest import TestCase <EOL> import pandas as pd <EOL> import numpy as np <EOL> try : <EOL> from StringIO import StringIO <EOL> except ImportError : <EOL> from io import StringIO <EOL> from pandashells . bin . p_sig_edit import ( <EOL> main , <EOL> ) <EOL> class MainUnitTest ( TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_from_input_to_output ( <EOL> self , arg_parser_mock , sig_edit_mock , io_lib_mock ) : <EOL> df_in = pd . DataFrame ( [ <EOL> { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:10> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:2> , '<STR_LIT:b>' : <NUM_LIT:20> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:3> , '<STR_LIT:b>' : <NUM_LIT:30> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:4> , '<STR_LIT:b>' : <NUM_LIT> } , <EOL> ] ) <EOL> args = MagicMock ( ) <EOL> args . sigma_thresh = [ <NUM_LIT> ] <EOL> args . cols = [ '<STR_LIT:a>' ] <EOL> args . max_iter = [ <NUM_LIT:20> ] <EOL> parser = MagicMock ( parse_args = MagicMock ( return_value = args ) ) <EOL> arg_parser_mock . return_value = parser <EOL> arg_parser_mock . parse_args = args <EOL> io_lib_mock . df_to_output = MagicMock ( ) <EOL> io_lib_mock . df_from_input = MagicMock ( return_value = df_in ) <EOL> main ( ) <EOL> sig_edit_mock . assert_called_with ( <NUM_LIT> , [ '<STR_LIT:a>' ] , df_in , max_iter = <NUM_LIT:20> ) <EOL> self . assertTrue ( io_lib_mock . df_to_output . called ) <EOL> class IntegrationTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . df = pd . DataFrame ( [ <EOL> { '<STR_LIT:a>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:2> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:2> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:2> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:2> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:6> } , <EOL> ] ) <EOL> def get_command_result ( self , cmd ) : <EOL> p = subprocess . Popen ( <EOL> [ '<STR_LIT>' , '<STR_LIT:-c>' , cmd ] , <EOL> stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> stdout , stderr = p . communicate ( <EOL> self . df . to_csv ( index = False ) . encode ( '<STR_LIT:utf-8>' ) ) <EOL> return stdout . decode ( '<STR_LIT:utf-8>' ) . strip ( ) <EOL> def test_editing ( self ) : <EOL> cmd = '<STR_LIT>' <EOL> df = pd . read_csv ( StringIO ( self . get_command_result ( cmd ) ) ) <EOL> self . assertTrue ( np . isnan ( df . a . iloc [ - <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( len ( df . dropna ( ) ) , <NUM_LIT:8> ) <EOL> def test_bad_iter ( self ) : <EOL> cmd = '<STR_LIT>' <EOL> with self . assertRaises ( ValueError ) : <EOL> pd . read_csv ( StringIO ( self . get_command_result ( cmd ) ) ) </s>
