Skip to content

Commit

Permalink
Disable automatic folder creation (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
alifbe authored Aug 14, 2023
1 parent 7bb5e7f commit 072bba6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
6 changes: 1 addition & 5 deletions pyscal/pyscalcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,7 @@ def pyscal_main(
print(wog_list.build_eclipse_data(family=family, slgof=slgof))
else:
if not Path(output).parent.exists():
logger.warning(
"Implicit directory creation is deprecated.\n"
"Please create the output directory prior to calling pyscal."
)
Path(output).parent.mkdir(exist_ok=True, parents=True)
raise IOError(f"Output directory not found '{Path(output).parent}'")
with open(output, "w", newline="\n", encoding="utf-8") as fh:
fh.write(wog_list.build_eclipse_data(family=family, slgof=slgof))
print("Written to " + output)
13 changes: 3 additions & 10 deletions pyscal/pyscallist.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,7 @@ def dump_family_1(self, filename: Optional[str] = None, slgof: bool = False) ->
string = self.build_eclipse_data(family=1, slgof=slgof)
if filename is not None:
if not Path(filename).parent.exists():
warnings.warn(
"Please create the output directory prior to calling pyscal.",
DeprecationWarning,
)
Path(filename).parent.mkdir(exist_ok=True, parents=True)
raise IOError(f"Output directory not found '{Path(filename).parent}'")
Path(filename).write_text(string, encoding="utf-8")
return string

Expand All @@ -310,11 +306,8 @@ def dump_family_2(self, filename: Optional[str] = None) -> str:
string = self.build_eclipse_data(family=2, slgof=False)
if filename is not None:
if not Path(filename).parent.exists():
warnings.warn(
"Please create the output directory prior to calling pyscal.",
DeprecationWarning,
)
Path(filename).parent.mkdir(exist_ok=True, parents=True)
raise IOError(f"Output directory not found '{Path(filename).parent}'")

Path(filename).write_text(string, encoding="utf-8")
return string

Expand Down
12 changes: 6 additions & 6 deletions tests/test_pyscalcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ def test_pyscal_client_static(tmp_path, caplog, default_loglevel, mocker):
"eclipse/include/props/relperm-fam2.inc",
],
)
pyscalcli.main()
assert Path("eclipse/include/props/relperm-fam2.inc").is_file()
assert not any(record.levelno == logging.ERROR for record in caplog.records)
with pytest.raises(SystemExit, match="Output directory not found"):
pyscalcli.main()
assert not Path("eclipse/include/props/relperm-fam2.inc").is_file()

caplog.clear()
mocker.patch(
"sys.argv", ["pyscal", str(relperm_file), "-o", "include/props/relperm.inc"]
)
pyscalcli.main()
assert Path("include/props/relperm.inc").is_file()
assert not any(record.levelno == logging.ERROR for record in caplog.records)
with pytest.raises(SystemExit, match="Output directory not found"):
pyscalcli.main()
assert not Path("include/props/relperm.inc").is_file()

caplog.clear()
# Check that we can read specific sheets
Expand Down
6 changes: 4 additions & 2 deletions tests/test_pyscallist.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,15 @@ def test_deprecated_dump_to_file(tmpdir):
assert PyscalList().build_eclipse_data(family=2) == ""

tmpdir.chdir()
Path("outputdir").mkdir(exist_ok=True)

with pytest.warns(DeprecationWarning):
pyscal_list.dump_family_1(filename="outputdir/output-fam1.inc")
assert "SWOF" in Path("outputdir/output-fam1.inc").read_text(encoding="utf8")

with pytest.warns(DeprecationWarning):
pyscal_list.dump_family_2(filename="anotherdir/output-fam2.inc")
assert "SOF3" in Path("anotherdir/output-fam2.inc").read_text(encoding="utf8")
pyscal_list.dump_family_2(filename="outputdir/output-fam2.inc")
assert "SOF3" in Path("outputdir/output-fam2.inc").read_text(encoding="utf8")

with pytest.warns(DeprecationWarning):
pyscal_list.SWOF(write_to_filename="swof.inc")
Expand Down

0 comments on commit 072bba6

Please sign in to comment.