# This file is part of Patsy
# Copyright (C) 2013 Nathaniel Smith <njs@pobox.com>
# See file LICENSE.txt for license information.

# Regression tests for fixed bugs (when not otherwise better covered somewhere
# else)

from patsy import (EvalEnvironment, dmatrix, build_design_matrices,
                   PatsyError, Origin)

def test_issue_11():
    # Give a sensible error message for level mismatches
    # (At some points we've failed to put an origin= on these errors)
    env = EvalEnvironment.capture()
    data = {"X" : [0,1,2,3], "Y" : [1,2,3,4]}
    formula = "C(X) + Y"
    new_data = {"X" : [0,0,1,2,3,3,4], "Y" : [1,2,3,4,5,6,7]}
    info = dmatrix(formula, data)
    try:
        build_design_matrices([info.design_info], new_data)
    except PatsyError as e:
        assert e.origin == Origin(formula, 0, 4)
    else:
        assert False

[((14, 10, 14, 35), 'patsy.EvalEnvironment.capture', 'EvalEnvironment.capture', ({}, {}), '()', False, 'from patsy import EvalEnvironment, dmatrix, build_design_matrices, PatsyError, Origin\n'), ((18, 11, 18, 33), 'patsy.dmatrix', 'dmatrix', ({(18, 19, 18, 26): 'formula', (18, 28, 18, 32): 'data'}, {}), '(formula, data)', False, 'from patsy import EvalEnvironment, dmatrix, build_design_matrices, PatsyError, Origin\n'), ((20, 8, 20, 59), 'patsy.build_design_matrices', 'build_design_matrices', ({(20, 30, 20, 48): '[info.design_info]', (20, 50, 20, 58): 'new_data'}, {}), '([info.design_info], new_data)', False, 'from patsy import EvalEnvironment, dmatrix, build_design_matrices, PatsyError, Origin\n'), ((22, 27, 22, 48), 'patsy.Origin', 'Origin', ({(22, 34, 22, 41): 'formula', (22, 43, 22, 44): '(0)', (22, 46, 22, 47): '(4)'}, {}), '(formula, 0, 4)', False, 'from patsy import EvalEnvironment, dmatrix, build_design_matrices, PatsyError, Origin\n')]