# -*- coding: utf-8 -*-


# OpenFisca -- A versatile microsimulation software
# By: OpenFisca Team <contact@openfisca.fr>
#
# Copyright (C) 2011, 2012, 2013, 2014 OpenFisca Team
# https://github.com/openfisca
#
# This file is part of OpenFisca.
#
# OpenFisca is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OpenFisca is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import json
import xml.etree.ElementTree

import openfisca_france
openfisca_france.init_country()

from openfisca_core import conv, legislations, legislationsxml, model


def test_legislation_xml_file():
    legislation_tree = xml.etree.ElementTree.parse(model.PARAM_FILE)
    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(legislation_tree.getroot(),
        state = conv.default_state)

    legislation_xml_json, errors = legislationsxml.validate_node_xml_json(legislation_xml_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_xml_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_xml_json, ensure_ascii = False,
                indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_xml_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    legislation_json = legislationsxml.transform_node_xml_json_to_json(legislation_xml_json)

    legislation_json, errors = legislations.validate_node_json(legislation_json, state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

@@ -903,16 +903,26 @@
 rt json%0A
+import os%0A
 import x
@@ -1072,16 +1072,1693 @@
 model%0A%0A%0A
+def test_ipp_legislation_xml_file():%0A    legislation_tree = xml.etree.ElementTree.parse(os.path.join(os.path.dirname(model.PARAM_FILE),%0A        'param_actu_IPP.xml'))%0A    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(legislation_tree.getroot(),%0A        state = conv.default_state)%0A%0A    legislation_xml_json, errors = legislationsxml.validate_node_xml_json(legislation_xml_json,%0A        state = conv.default_state)%0A    if errors is not None:%0A        errors = conv.embed_error(legislation_xml_json, 'errors', errors)%0A        if errors is None:%0A            raise ValueError(unicode(json.dumps(legislation_xml_json, ensure_ascii = False,%0A                indent = 2)).encode('utf-8'))%0A        raise ValueError(u'%7B0%7D for: %7B1%7D'.format(%0A            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),%0A            unicode(json.dumps(legislation_xml_json, ensure_ascii = False, indent = 2)),%0A            ).encode('utf-8'))%0A%0A    legislation_json = legislationsxml.transform_node_xml_json_to_json(legislation_xml_json)%0A%0A    legislation_json, errors = legislations.validate_node_json(legislation_json, state = conv.default_state)%0A    if errors is not None:%0A        errors = conv.embed_error(legislation_json, 'errors', errors)%0A        if errors is None:%0A            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode('utf-8'))%0A        raise ValueError(u'%7B0%7D for: %7B1%7D'.format(%0A            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),%0A            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),%0A            ).encode('utf-8'))%0A%0A%0A
 def test

Add test to validate param_actu_IPP.xml file.