Skip to content

Commit

Permalink
use absolute paths to data files in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegrabowski committed Feb 5, 2023
1 parent 68953b3 commit 8acf7bc
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 33 deletions.
33 changes: 33 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "70...100"
status:
project:
default:
# basic
target: auto
threshold: 1%
base: auto
patch:
default:
# basic
target: 50%
threshold: 1%
base: auto

ignore:
- "gEconpy/tests/*"
- "gEconpy/examples/*"
- "gEconpy/GCN FIles/*"

comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false # if true: only post the comment if coverage changes
require_base: no # [yes :: must have a base report to post]
require_head: yes # [yes :: must have a head report to post]
branches: null # branch names that can post comment
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,3 @@ install_requires =

[options.packages.find]
exclude = tests*

;[options.entry_points]
;numba_extensions =
; init = gEconpy:init
File renamed without changes.
10 changes: 7 additions & 3 deletions tests/test_block.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import unittest
from pathlib import Path

import numpy as np
import sympy as sp
Expand All @@ -8,10 +10,12 @@
from gEconpy.parser import constants, file_loaders, gEcon_parser
from gEconpy.shared.utilities import set_equality_equals_zero, unpack_keys_and_values

ROOT = Path(__file__).parent.absolute()


class BlockTestCases(unittest.TestCase):
def setUp(self):
test_file = file_loaders.load_gcn("Test GCNs/One_Block_Simple_2.gcn")
test_file = file_loaders.load_gcn(os.path.join(ROOT, "Test GCNs/One_Block_Simple_2.gcn"))
parser_output, prior_dict = gEcon_parser.preprocess_gcn(test_file)
block_dict = gEcon_parser.split_gcn_into_block_dictionary(parser_output)
block_dict = gEcon_parser.parsed_block_to_dict(block_dict["HOUSEHOLD"])
Expand Down Expand Up @@ -171,7 +175,7 @@ def test_Household_FOC(self):
self.assertIn(np.float32(solution.subs(sub_dict)), subbed_system)

def test_firm_block_lagrange_parsing(self):
test_file = file_loaders.load_gcn("Test GCNs/Two_Block_RBC_1.gcn")
test_file = file_loaders.load_gcn(os.path.join(ROOT, "Test GCNs/Two_Block_RBC_1.gcn"))
parser_output, prior_dict = gEcon_parser.preprocess_gcn(test_file)
block_dict = gEcon_parser.split_gcn_into_block_dictionary(parser_output)
block_dict = gEcon_parser.parsed_block_to_dict(block_dict["FIRM"])
Expand All @@ -194,7 +198,7 @@ def test_firm_block_lagrange_parsing(self):
self.assertEqual((block._build_lagrangian() - L).simplify(), 0)

def test_firm_FOC(self):
test_file = file_loaders.load_gcn("Test GCNs/Two_Block_RBC_1.gcn")
test_file = file_loaders.load_gcn(os.path.join(ROOT, "Test GCNs/Two_Block_RBC_1.gcn"))
parser_output, prior_dict = gEcon_parser.preprocess_gcn(test_file)
block_dict = gEcon_parser.split_gcn_into_block_dictionary(parser_output)
firm_dict = gEcon_parser.parsed_block_to_dict(block_dict["FIRM"])
Expand Down
6 changes: 5 additions & 1 deletion tests/test_estimation.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import os
import unittest
from pathlib import Path

import numpy as np

from gEconpy.classes.model import gEconModel
from gEconpy.estimation.estimate import build_and_solve, build_Q_and_H
from gEconpy.estimation.estimation_utilities import extract_sparse_data_from_model

ROOT = Path(__file__).parent.absolute()


class TestEstimationHelpers(unittest.TestCase):
def setUp(self) -> None:
file_path = "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn"
file_path = os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn")
self.model = gEconModel(file_path, verbose=False)
self.model.steady_state(verbose=False)
self.model.solve_model(verbose=False)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_kalman_filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import unittest
from pathlib import Path

import numpy as np

Expand All @@ -10,10 +12,12 @@
)
from gEconpy.estimation.kalman_filter import kalman_filter, univariate_kalman_filter

ROOT = Path(__file__).parent.absolute()


class BasicFunctionalityTests(unittest.TestCase):
def setUp(self):
file_path = "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn"
file_path = os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn")
self.model = gEconModel(file_path, verbose=False)
self.model.steady_state(verbose=False)
self.model.solve_model(verbose=False)
Expand Down Expand Up @@ -184,7 +188,7 @@ def test_likelihood_with_missing(self):

class TestModelEstimation(unittest.TestCase):
def setUp(self):
file_path = "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn"
file_path = os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn")
self.model = gEconModel(file_path, verbose=False)
self.model.steady_state(verbose=False)
self.model.solve_model(verbose=False)
Expand Down
17 changes: 11 additions & 6 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import os
import unittest
from pathlib import Path

import numpy as np
import pandas as pd
import sympy as sp
from numpy.testing import assert_allclose

from gEconpy.classes.model import gEconModel
from gEconpy.classes.time_aware_symbol import TimeAwareSymbol
from gEconpy.parser.constants import DEFAULT_ASSUMPTIONS
from gEconpy.shared.utilities import string_keys_to_sympy

ROOT = Path(__file__).parent.absolute()


class ModelClassTestsOne(unittest.TestCase):
def setUp(self):
file_path = "Test GCNs/One_Block_Simple_2.gcn"
file_path = os.path.join(ROOT, "Test GCNs/One_Block_Simple_2.gcn")
self.model = gEconModel(file_path, verbose=False)

def test_model_options(self):
Expand Down Expand Up @@ -52,7 +55,9 @@ def test_model_file_loading(self):
)

def test_conflicting_assumptions_are_removed(self):
model = gEconModel("Test GCNs/conflicting_assumptions.gcn", verbose=False)
model = gEconModel(
os.path.join(ROOT, "Test GCNs/conflicting_assumptions.gcn"), verbose=False
)
self.assertTrue("real" not in model.assumptions["TC"].keys())
self.assertTrue("imaginary" in model.assumptions["TC"].keys())
self.assertTrue(model.assumptions["TC"]["imaginary"])
Expand Down Expand Up @@ -179,7 +184,7 @@ def test_solve_model_cycle_reduction(self):

class ModelClassTestsTwo(unittest.TestCase):
def setUp(self):
file_path = "Test GCNs/Two_Block_RBC_1.gcn"
file_path = os.path.join(ROOT, "Test GCNs/Two_Block_RBC_1.gcn")
self.model = gEconModel(file_path, verbose=False)

def test_model_options(self):
Expand Down Expand Up @@ -336,7 +341,7 @@ def test_solve_model_cycle_reduction(self):

class ModelClassTestsThree(unittest.TestCase):
def setUp(self):
file_path = "Test GCNs/Full_New_Keyensian.gcn"
file_path = os.path.join(ROOT, "Test GCNs/Full_New_Keyensian.gcn")
self.model = gEconModel(
file_path, verbose=False, simplify_constants=False, simplify_tryreduce=False
)
Expand Down Expand Up @@ -532,7 +537,7 @@ def test_solvers_agree(self):
# class ModelWithSteadyStateTest(unittest.TestCase):
#
# def setUp(self):
# file_path = 'Test GCNs/One_Block_Simple_1_w_Steady_State.gcn'
# file_path = os.path.join(ROOT, 'Test GCNs/One_Block_Simple_1_w_Steady_State.gcn')
# self.model = gEconModel(file_path, verbose=False)
#
# def test_steady_state_block(self):
Expand Down
18 changes: 12 additions & 6 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import unittest
from collections import defaultdict
from pathlib import Path

import pyparsing
import sympy as sp
Expand All @@ -10,10 +12,14 @@
from gEconpy.parser.constants import DEFAULT_ASSUMPTIONS
from gEconpy.parser.parse_distributions import CompositeDistribution

ROOT = Path(__file__).parent.absolute()


class ParserDistributionCases(unittest.TestCase):
def setUp(self):
self.model = file_loaders.load_gcn("Test GCNs/One_Block_Simple_1_w_Distributions.gcn")
self.model = file_loaders.load_gcn(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Distributions.gcn")
)

def test_distribution_extraction_simple(self):
test_str = "alpha ~ Normal(0, 1) = 0.5;"
Expand Down Expand Up @@ -126,7 +132,7 @@ def test_parse_gcn(self):
"""

parser_output, _ = gEcon_parser.preprocess_gcn(test_file)
with open("Test Answer Strings/test_parse_gcn.txt") as file:
with open(os.path.join(ROOT, "Test Answer Strings/test_parse_gcn.txt")) as file:
expected_result = file.read()

self.assertEqual(parser_output, expected_result)
Expand Down Expand Up @@ -180,16 +186,16 @@ def test_block_deletion(self):
self.assertEqual(result.strip(), "tryreduce { Div[], TC[] ; };")

result = parse_plaintext.delete_block(parser_output, "tryreduce")
with open("Test Answer Strings/test_block_deletion.txt") as file:
with open(os.path.join(ROOT, "Test Answer Strings/test_block_deletion.txt")) as file:
expected_result = file.read()

self.assertEqual(result.strip(), expected_result)

def test_split_gcn_by_blocks(self):
test_file = file_loaders.load_gcn("Test GCNs/One_Block_Simple_1.gcn")
test_file = file_loaders.load_gcn(os.path.join(ROOT, "Test GCNs/One_Block_Simple_1.gcn"))
parser_output, _ = gEcon_parser.preprocess_gcn(test_file)

with open("Test Answer Strings/test_split_gcn_by_blocks.txt") as file:
with open(os.path.join(ROOT, "Test Answer Strings/test_split_gcn_by_blocks.txt")) as file:
expected_result = file.read()

block_dict = gEcon_parser.split_gcn_into_block_dictionary(parser_output)
Expand Down Expand Up @@ -233,7 +239,7 @@ def test_parse_block_to_dict(self):
[["U[]", "=", "u[]", "+", "beta", "*", "E[]", "[", "U[1]", "]"]],
)

test_file = file_loaders.load_gcn("Test GCNs/Two_Block_RBC_1.gcn")
test_file = file_loaders.load_gcn(os.path.join(ROOT, "Test GCNs/Two_Block_RBC_1.gcn"))
parser_output, _ = gEcon_parser.preprocess_gcn(test_file)
block_dict = gEcon_parser.split_gcn_into_block_dictionary(parser_output)
household = gEcon_parser.parsed_block_to_dict(block_dict["HOUSEHOLD"])
Expand Down
43 changes: 32 additions & 11 deletions tests/test_steady_state.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import os
import unittest
from pathlib import Path

import sympy as sp
from scipy import optimize

from gEconpy.classes.model import gEconModel

ROOT = Path(__file__).parent.absolute()


class SteadyStateModelOne(unittest.TestCase):
def setUp(self):
self.model = gEconModel("Test GCNs/One_Block_Simple_1.gcn", verbose=False)
self.model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1.gcn"), verbose=False
)

def test_successfully_solves_ss(self):
self.model.steady_state(verbose=False, apply_user_simplifications=False)
self.assertTrue(self.model.steady_state_solved)

def test_solve_ss_with_partial_user_solution(self):
self.model = gEconModel("Test GCNs/One_Block_Simple_1.gcn", verbose=False)
self.model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1.gcn"), verbose=False
)
self.model.steady_state(verbose=False, apply_user_simplifications=True)
self.assertTrue(self.model.steady_state_solved)

Expand Down Expand Up @@ -43,8 +51,9 @@ def test_steady_state_matches_analytic(self):

class SteadyStateModelTwo(unittest.TestCase):
def setUp(self):
self.model = gEconModel("Test GCNs/One_Block_Simple_2.gcn", verbose=False)
# self.solver = SteadyStateSolver(model)
self.model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_2.gcn"), verbose=False
)

def test_successfully_solves_ss(self):
self.model.steady_state(verbose=False, apply_user_simplifications=False)
Expand Down Expand Up @@ -96,7 +105,7 @@ def test_steady_state_matches_analytic(self):

class SteadyStateModelThree(unittest.TestCase):
def setUp(self):
self.model = gEconModel("Test GCNs/Two_Block_RBC_1.gcn", verbose=False)
self.model = gEconModel(os.path.join(ROOT, "Test GCNs/Two_Block_RBC_1.gcn"), verbose=False)
self.model.steady_state(verbose=False)

def test_successfully_solves_ss(self):
Expand Down Expand Up @@ -157,7 +166,9 @@ def test_steady_state_matches_analytic(self):

class SteadyStateModelFour(unittest.TestCase):
def setUp(self):
self.model = gEconModel("Test GCNs/Full_New_Keyensian.gcn", verbose=False)
self.model = gEconModel(
os.path.join(ROOT, "Test GCNs/Full_New_Keyensian.gcn"), verbose=False
)
self.model.steady_state(verbose=False)

def test_successfully_solves_ss(self):
Expand Down Expand Up @@ -280,29 +291,39 @@ def test_steady_state_matches_analytic(self):

class SteadyStateWithUserError(unittest.TestCase):
def setUp(self):
self.model = gEconModel("Test GCNs/One_Block_Simple_1_ss_Error.gcn", verbose=False)
self.model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_ss_Error.gcn"), verbose=False
)

def test_raises_on_nonzero_resids(self):
self.assertRaises(ValueError, self.model.steady_state, apply_user_simplifications=True)


class FullyUserDefinedSteadyState(unittest.TestCase):
def test_ss_solves_from_user_definition(self):
model = gEconModel("Test GCNs/One_Block_Simple_1_w_Steady_State.gcn", verbose=False)
model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn"), verbose=False
)
model.steady_state(apply_user_simplifications=True, verbose=False)
self.assertTrue(model.steady_state_solved)

def test_ss_solves_when_ignoring_user_definition(self):
model = gEconModel("Test GCNs/One_Block_Simple_1_w_Steady_State.gcn", verbose=False)
model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn"), verbose=False
)
model.steady_state(apply_user_simplifications=False, verbose=False)
self.assertTrue(model.steady_state_solved)

def test_solver_matches_user_solution(self):
model = gEconModel("Test GCNs/One_Block_Simple_1_w_Steady_State.gcn", verbose=False)
model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn"), verbose=False
)
model.steady_state(apply_user_simplifications=False, verbose=False)
ss_dict_numeric = model.steady_state_dict.copy()

model = gEconModel("Test GCNs/One_Block_Simple_1_w_Steady_State.gcn", verbose=False)
model = gEconModel(
os.path.join(ROOT, "Test GCNs/One_Block_Simple_1_w_Steady_State.gcn"), verbose=False
)
model.steady_state(apply_user_simplifications=True, verbose=False)
ss_dict_user = model.steady_state_dict.copy()

Expand Down

0 comments on commit 8acf7bc

Please sign in to comment.