|
| 1 | +################################################################################# |
| 2 | +# FOQUS Copyright (c) 2012 - 2024, by the software owners: Oak Ridge Institute |
| 3 | +# for Science and Education (ORISE), TRIAD National Security, LLC., Lawrence |
| 4 | +# Livermore National Security, LLC., The Regents of the University of |
| 5 | +# California, through Lawrence Berkeley National Laboratory, Battelle Memorial |
| 6 | +# Institute, Pacific Northwest Division through Pacific Northwest National |
| 7 | +# Laboratory, Carnegie Mellon University, West Virginia University, Boston |
| 8 | +# University, the Trustees of Princeton University, The University of Texas at |
| 9 | +# Austin, URS Energy & Construction, Inc., et al. All rights reserved. |
| 10 | +# |
| 11 | +# Please see the file LICENSE.md for full copyright and license information, |
| 12 | +# respectively. This file is also available online at the URL |
| 13 | +# "https://github.com/CCSI-Toolset/FOQUS". |
| 14 | +################################################################################# |
| 15 | +from importlib import resources |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +import pandas as pd |
| 19 | + |
| 20 | +from foqus_lib.framework.sdoe.df_utils import write, load, merge, check |
| 21 | + |
| 22 | + |
| 23 | +def test_write(): |
| 24 | + fname = "test_data.csv" |
| 25 | + df = pd.DataFrame([(1, 1), (2, 2), (3, 3), (4, 4)]) |
| 26 | + |
| 27 | + write(fname, df) |
| 28 | + |
| 29 | + obj = Path(fname) |
| 30 | + |
| 31 | + test_results = obj.exists() |
| 32 | + |
| 33 | + # Clean up |
| 34 | + obj.unlink() |
| 35 | + |
| 36 | + assert test_results |
| 37 | + |
| 38 | + |
| 39 | +def test_load(): |
| 40 | + fname = "candidates_usf.csv" |
| 41 | + copy_from_package(fname) |
| 42 | + |
| 43 | + df = load(fname) |
| 44 | + |
| 45 | + assert df is not None |
| 46 | + |
| 47 | + |
| 48 | +def test_merge(): |
| 49 | + fnames = ["candidates_usf.csv", "previous_data.csv"] |
| 50 | + for fname in fnames: |
| 51 | + copy_from_package(fname) |
| 52 | + |
| 53 | + df = merge(fnames) |
| 54 | + |
| 55 | + assert df is not None |
| 56 | + |
| 57 | + |
| 58 | +def test_check(): |
| 59 | + cfiles = ["cand1.csv", "cand2.csv"] |
| 60 | + hfiles = ["prev1.csv", "prev2.csv"] |
| 61 | + |
| 62 | + for cfile in cfiles: |
| 63 | + copy_from_package(cfile) |
| 64 | + |
| 65 | + for hfile in hfiles: |
| 66 | + copy_from_package(hfile) |
| 67 | + |
| 68 | + cand_df, hist_df = check(cfiles, hfiles) |
| 69 | + |
| 70 | + assert cand_df is not None |
| 71 | + assert hist_df is not None |
| 72 | + |
| 73 | + |
| 74 | +def copy_from_package(file_name: str) -> None: |
| 75 | + content = resources.read_text(__package__, file_name) |
| 76 | + Path(file_name).write_text(content) |
0 commit comments