Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelLucaAdams committed Jul 23, 2024
1 parent a83103f commit ae70f7b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
12 changes: 8 additions & 4 deletions test/cone.deck
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ begin:dist_fn
resolution1 = 1
resolution2 = 100

include_species:electron
include_species:proton
include_species:Electron
include_species:Proton

identify:Photon
end:dist_fn


Expand All @@ -145,6 +147,8 @@ begin:dist_fn
resolution2 = 100
resolution3 = 100

include_species:electron
include_species:proton
include_species:Electron
include_species:Proton

identify:Photon
end:dist_fn
34 changes: 25 additions & 9 deletions test/test_read.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from epydeck import loads, load
import epydeck

import pathlib

Expand All @@ -15,7 +15,7 @@ def test_basic_block():
end:block
"""

data = loads(text)
data = epydeck.loads(text)

expected = {
"block": {
Expand All @@ -41,7 +41,7 @@ def test_repeated_line():
end:block
"""

data = loads(text)
data = epydeck.loads(text)

expected = {"block": {"a": 1, "b": 2, "c": [3, 4]}}

Expand All @@ -65,7 +65,7 @@ def test_repeated_block():
end:block
"""

data = loads(text)
data = epydeck.loads(text)

expected = {
"block": {
Expand All @@ -81,14 +81,30 @@ def test_include_species():
text = """
begin:dist_fn
a = 1
include_species: electron
include_species: proton
include_species:Electron
include_species:Proton
end:dist_fn
"""

data = loads(text)
data = epydeck.loads(text)

expected = {"dist_fn": {"a": 1, "include_species": ["electron", "proton"]}}
expected = {"dist_fn": {"a": 1, "include_species": ["Electron", "Proton"]}}

assert expected == data


def test_include_identify():
text = """
begin:dist_fn
a = 1
identify:Electron
identify:Proton
end:dist_fn
"""

data = epydeck.loads(text)

expected = {"dist_fn": {"a": 1, "identify": ["Electron", "Proton"]}}

assert expected == data

Expand All @@ -97,7 +113,7 @@ def test_read_file():
filename = pathlib.Path(__file__).parent / "cone.deck"

with open(filename) as f:
data = load(f)
data = epydeck.load(f)

assert "control" in data
assert "species" in data
Expand Down
39 changes: 28 additions & 11 deletions test/test_write.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from epydeck import dumps, dump, load

import epydeck
from textwrap import dedent


Expand Down Expand Up @@ -28,7 +27,7 @@ def test_basic_block():
"f": True,
}
}
result = dumps(deck)
result = epydeck.dumps(deck)

assert expected == result

Expand All @@ -47,7 +46,7 @@ def test_repeated_line():
)

deck = {"block": {"a": 1, "b": 2, "c": [3, 4]}}
result = dumps(deck)
result = epydeck.dumps(deck)

assert expected == result

Expand Down Expand Up @@ -78,7 +77,7 @@ def test_repeated_block():
"second": {"name": "second", "a": 4, "b": 5, "c": 6},
}
}
result = dumps(deck)
result = epydeck.dumps(deck)

assert expected == result

Expand All @@ -88,15 +87,33 @@ def test_include_species():
"""\
begin:dist_fn
a = 1
include_species: electron
include_species: proton
include_species:Electron
include_species:Proton
end:dist_fn
"""
)

deck = {"dist_fn": {"a": 1, "include_species": ["Electron", "Proton"]}}
result = epydeck.dumps(deck)

assert expected == result


def test_include_identify():
expected = dedent(
"""\
begin:dist_fn
a = 1
identify:Electron
identify:Proton
end:dist_fn
"""
)

deck = {"dist_fn": {"a": 1, "include_species": ["electron", "proton"]}}
result = dumps(deck)
deck = {"dist_fn": {"a": 1, "identify": ["Electron", "Proton"]}}
result = epydeck.dumps(deck)

assert expected == result

Expand All @@ -119,9 +136,9 @@ def test_write_to_file(tmp_path):

filename = tmp_path / "test.in"
with open(filename, "w") as f:
dump(deck, f)
epydeck.dump(deck, f)

with open(filename, "r") as f:
data = load(f)
data = epydeck.load(f)

assert data == deck

0 comments on commit ae70f7b

Please sign in to comment.