import os

from openfisca_core.parameters import load_parameter_file
from openfisca_web_api.loader.parameters import build_api_values_history, get_value


dir_path = os.path.join(os.path.dirname(__file__), 'assets')


def test_build_api_values_history():
    file_path = os.path.join(dir_path, 'test_helpers.yaml')
    parameter = load_parameter_file(name='dummy_name', file_path=file_path)

    values = {
        '2017-01-01': 0.02,
        '2015-01-01': 0.04,
        '2013-01-01': 0.03,
        }
    assert build_api_values_history(parameter) == values


def test_build_api_values_history_with_stop_date():
    file_path = os.path.join(dir_path, 'test_helpers_with_stop_date.yaml')
    parameter = load_parameter_file(name='dummy_name', file_path=file_path)

    values = {
        '2018-01-01': None,
        '2017-01-01': 0.02,
        '2015-01-01': 0.04,
        '2013-01-01': 0.03,
        }

    assert build_api_values_history(parameter) == values


def test_get_value():
    values = {'2013-01-01': 0.03, '2017-01-01': 0.02, '2015-01-01': 0.04}

    assert get_value('2013-01-01', values) == 0.03
    assert get_value('2014-01-01', values) == 0.03
    assert get_value('2015-02-01', values) == 0.04
    assert get_value('2016-12-31', values) == 0.04
    assert get_value('2017-01-01', values) == 0.02
    assert get_value('2018-01-01', values) == 0.02


def test_get_value_with_none():
    values = {'2015-01-01': 0.04, '2017-01-01': None}

    assert get_value('2016-12-31', values) == 0.04
    assert get_value('2017-01-01', values) is None
    assert get_value('2011-01-01', values) is None

@@ -23,31 +23,30 @@
 sca_
-core.paramet
+web_api.load
 er
-s
  import 
 load
@@ -41,21 +41,16 @@
  import 
-load_
 paramete
@@ -50,21 +50,18 @@
 arameter
-_file
+s%0A
 %0Afrom op
@@ -68,30 +68,20 @@
 enfisca_
-web_api.loader
+core
 .paramet
@@ -95,42 +95,26 @@
 ort 
-build_api_values_history, get_valu
+load_parameter_fil
 e%0A%0A%0A
@@ -462,32 +462,43 @@
    %7D%0A    assert 
+parameters.
 build_api_values
@@ -882,16 +882,27 @@
  assert 
+parameters.
 build_ap
@@ -1041,32 +1041,43 @@
 04%7D%0A%0A    assert 
+parameters.
 get_value('2013-
@@ -1103,32 +1103,43 @@
 0.03%0A    assert 
+parameters.
 get_value('2014-
@@ -1165,32 +1165,43 @@
 0.03%0A    assert 
+parameters.
 get_value('2015-
@@ -1227,32 +1227,43 @@
 0.04%0A    assert 
+parameters.
 get_value('2016-
@@ -1289,32 +1289,43 @@
 0.04%0A    assert 
+parameters.
 get_value('2017-
@@ -1351,32 +1351,43 @@
 0.02%0A    assert 
+parameters.
 get_value('2018-
@@ -1502,32 +1502,43 @@
 ne%7D%0A%0A    assert 
+parameters.
 get_value('2016-
@@ -1564,32 +1564,43 @@
 0.04%0A    assert 
+parameters.
 get_value('2017-
@@ -1634,16 +1634,27 @@
  assert 
+parameters.
 get_valu

Fix import styles