generated from ihmeuw-msca/pypkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ihmeuw-msca/bugfix/tests
bugfix/tests
- Loading branch information
Showing
2 changed files
with
82 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
EXAMPLES = Path(__file__).resolve().parent / "examples" | ||
|
||
|
||
class Example1D: | ||
def __init__(self): | ||
self.df_obs = pd.read_csv(EXAMPLES / "example_1D" / "observations.csv") | ||
self.df_margin = pd.read_csv(EXAMPLES / "example_1D" / "margin.csv") | ||
|
||
|
||
class Example2D: | ||
def __init__(self): | ||
self.df_obs = pd.read_csv(EXAMPLES / "example_2D" / "observations.csv") | ||
self.df_margins_1 = pd.read_csv( | ||
EXAMPLES / "example_2D" / "margins_1.csv" | ||
) | ||
self.df_margins_2 = pd.read_csv( | ||
EXAMPLES / "example_2D" / "margins_2.csv" | ||
) | ||
|
||
|
||
class Example3D: | ||
def __init__(self): | ||
self.df_obs = pd.read_csv(EXAMPLES / "example_3D" / "observations.csv") | ||
self.df_margins_1 = pd.read_csv( | ||
EXAMPLES / "example_3D" / "margins_1.csv" | ||
) | ||
self.df_margins_2 = pd.read_csv( | ||
EXAMPLES / "example_3D" / "margins_2.csv" | ||
) | ||
self.df_margins_3 = pd.read_csv( | ||
EXAMPLES / "example_3D" / "margins_3.csv" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def example_1D(): | ||
return Example1D() | ||
|
||
|
||
@pytest.fixture | ||
def example_2D(): | ||
return Example2D() | ||
|
||
|
||
@pytest.fixture | ||
def example_3D(): | ||
return Example3D() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
import pytest | ||
import numpy as np | ||
import os | ||
import pandas as pd | ||
|
||
from raking.run_raking import run_raking | ||
|
||
def test_run_raking_1D(): | ||
df_obs = pd.read_csv('examples/example_1D/observations.csv') | ||
df_margin = pd.read_csv('examples/example_1D/margin.csv') | ||
run_raking(1, 'examples/example_1D', df_obs, [df_margin], ['var1']) | ||
|
||
def test_run_raking_2D(): | ||
df_obs = pd.read_csv('examples/example_2D/observations.csv') | ||
df_margins_1 = pd.read_csv('examples/example_2D/margins_1.csv') | ||
df_margins_2 = pd.read_csv('examples/example_2D/margins_2.csv') | ||
run_raking(2, 'examples/example_2D', df_obs, [df_margins_1, df_margins_2], ['var1', 'var2']) | ||
def test_run_raking_1D(tmp_path, example_1D): | ||
run_raking( | ||
1, | ||
str(tmp_path), | ||
example_1D.df_obs, | ||
[example_1D.df_margin], | ||
["var1"], | ||
) | ||
|
||
|
||
def test_run_raking_2D(tmp_path, example_2D): | ||
run_raking( | ||
2, | ||
str(tmp_path), | ||
example_2D.df_obs, | ||
[example_2D.df_margins_1, example_2D.df_margins_2], | ||
["var1", "var2"], | ||
) | ||
|
||
def test_run_raking_3D(): | ||
df_obs = pd.read_csv('examples/example_3D/observations.csv') | ||
df_margins_1 = pd.read_csv('examples/example_3D/margins_1.csv') | ||
df_margins_2 = pd.read_csv('examples/example_3D/margins_2.csv') | ||
df_margins_3 = pd.read_csv('examples/example_3D/margins_3.csv') | ||
run_raking(3, 'examples/example_3D', df_obs, [df_margins_1, df_margins_2, df_margins_3], ['var1', 'var2', 'var3']) | ||
|
||
def test_run_raking_3D(tmp_path, example_3D): | ||
run_raking( | ||
3, | ||
str(tmp_path), | ||
example_3D.df_obs, | ||
[ | ||
example_3D.df_margins_1, | ||
example_3D.df_margins_2, | ||
example_3D.df_margins_3, | ||
], | ||
["var1", "var2", "var3"], | ||
) |