forked from popsim-consortium/demes-python
-
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.
Use __all__ and __dir__ to hide non-public API.
Closes popsim-consortium#324. Note that non-public symbols are still accessible when referred to explicitly by name. But here we use the module-level __dir__() function to define which symbols are seen when using dir(<module-name>). This is a Python >= 3.7 only feature, but the function is just ignored on Python 3.6.
- Loading branch information
1 parent
8ec4796
commit 9e0a277
Showing
4 changed files
with
132 additions
and
2 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
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
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
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,90 @@ | ||
import pathlib | ||
import tempfile | ||
|
||
import pytest | ||
from demes import * | ||
|
||
|
||
def test_builder(): | ||
b = Builder() | ||
b.add_deme("A", epochs=[dict(start_size=100)]) | ||
b.resolve() | ||
|
||
|
||
def test_dumps_and_loads(): | ||
b = Builder() | ||
b.add_deme("A", epochs=[dict(start_size=100)]) | ||
graph1 = b.resolve() | ||
dump_str = dumps(graph1) | ||
graph2 = loads(dump_str) | ||
graph1.assert_close(graph2) | ||
|
||
|
||
def test_dump_and_load(): | ||
b = Builder() | ||
b.add_deme("A", epochs=[dict(start_size=100)]) | ||
graph1 = b.resolve() | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
tmpfile = pathlib.Path(tmpdir) / "temp.yaml" | ||
dump(graph1, tmpfile) | ||
graph2 = load(tmpfile) | ||
graph1.assert_close(graph2) | ||
|
||
|
||
def test_public_symbols(): | ||
Builder | ||
Epoch | ||
AsymmetricMigration | ||
Pulse | ||
Deme | ||
Graph | ||
Split | ||
Branch | ||
Merge | ||
Admix | ||
|
||
load_asdict | ||
loads_asdict | ||
load | ||
loads | ||
load_all | ||
dump | ||
dumps | ||
dump_all | ||
|
||
from_ms | ||
|
||
|
||
def test_nonpublic_symbols(): | ||
with pytest.raises(NameError): | ||
demes | ||
with pytest.raises(NameError): | ||
load_dump | ||
with pytest.raises(NameError): | ||
ms | ||
with pytest.raises(NameError): | ||
prec32 | ||
|
||
|
||
def test_demes_dir(): | ||
import demes | ||
|
||
dir_demes = set(dir(demes)) | ||
assert "load" in dir_demes | ||
assert "dump" in dir_demes | ||
assert "loads" in dir_demes | ||
assert "dumps" in dir_demes | ||
|
||
assert "demes" not in dir_demes | ||
assert "load_dump" not in dir_demes | ||
assert "ms" not in dir_demes | ||
assert "graphs" not in dir_demes | ||
assert "prec32" not in dir_demes | ||
|
||
|
||
def test_hypothesis_strategy_dir(): | ||
import demes.hypothesis_strategies | ||
|
||
dir_demes_hs = set(dir(demes.hypothesis_strategies)) | ||
assert "graphs" in dir_demes_hs | ||
assert "prec32" not in dir_demes_hs |