def test_multiple_stmts_with_pipeline(self, dataframe, csv_file_comma): path = str(csv_file_comma) src = """ df = read_file("%s") pipeline(df): { drop(.name)} """ % path df_res = read_file(path) result = drop(df_res, Col('name')) assert run(src).equals(result)
def test_attr_call_on_var(self, dataframe): e = env() e[Symbol('df')] = dataframe assert run('df.columns').equals(dataframe.columns)
def test_sugar_col_returns_Col_instance(self): assert isinstance(run('.col'), Col)
def test_sugar_col_returns_Col_with_right_name(self): col = run('.col') assert col.name == 'col'
def test_pipeline_execute_stmts(self, dataframe): e = env() e[Symbol('df')] = dataframe assert run('pipeline(df): {drop(.name)}', env=e).equals( drop(dataframe, Col('name')))
def test_pipeline_execute_multiple_stmts(self, dataframe): e = env() e[Symbol('df')] = dataframe assert run('pipeline(df): {drop(.name) drop(.floats)}', env=e).equals( drop(dataframe, [Col('name'), Col('floats')]))
def test_precedence_with_parentheses_number_expression(self): assert run('(2 + 3) * 5') == 25 assert run('(6 / 2) * 6') == 18
def test_pipeline_raise_error_on_undeclared_dataframe(self): with pytest.raises(NameError): run('pipeline(df): {drop(.name)}')
def test_number_div_expression(self): assert run('6 / 2') == 3 assert run('12 / 2 / 3') == 2
def test_precedence_number_expression(self): assert run('2 * 3 + 5') == 11 assert run('2 / 2 + 3') == 4
def test_number_mult_expression(self): assert run('2 * 3') == 6 assert run('2 * 3 * 4') == 24
def test_number_sub_expression(self): assert run('1 - 2') == -1 assert run('10 - 2 - 1') == 7
def test_number_sum_expressions(self): assert run('1 + 2') == 3 assert run('1 + 2 + 3') == 6
def test_assing_variable_using_expr(self): e = env() run('x = 1 + 2 + 3', e) assert e[Symbol('x')] == 6
def test_assign_variable_add_to_env(self): e = env() run('x = 1', e) assert e[Symbol('x')] == 1