Skip to content

Commit

Permalink
TST: fix cluster tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lbluque committed May 29, 2024
1 parent e4fc0a6 commit 7800edd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions smol/cofe/space/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def from_file(cls, filename: str):
"""
filename = str(filename)

with zopen(filename) as f:
contents = f.read()
fname = filename.lower()
with zopen(filename, mode="rt", errors="replace") as file:
contents = file.read()
fname = os.path.basename(filename)

if fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"):
return cls.from_str(contents, fmt="json")
Expand Down
28 changes: 14 additions & 14 deletions tests/test_cofe/test_cluster.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
import os
from itertools import combinations

import numpy as np
import pytest
from ruamel import yaml
from ruamel.yaml import YAML

from smol.cofe.space import Cluster
from smol.cofe.space.domain import get_site_spaces
Expand Down Expand Up @@ -70,23 +69,24 @@ def test_to_from(cluster, tmpdir):
cluster2 = Cluster.from_str(yml, "yaml")
assert cluster == cluster2

YAML()
with open(os.path.join(tmpdir, "cluster.yaml"), "w") as f:
yaml.dump(yml, f)
f.write(yml)
with open(os.path.join(tmpdir, "cluster.json"), "w") as f:
json.dump(js, f)
f.write(js)

# cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.yaml"))
# assert cluster == cluster2
# cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.json"))
# assert cluster == cluster2
cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.yaml"))
assert cluster == cluster2
cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.json"))
assert cluster == cluster2

# cluster.to("yaml", os.path.join(tmpdir, "cluster.yaml"))
# cluster.to("json", os.path.join(tmpdir, "cluster.json"))
cluster.to("yaml", os.path.join(tmpdir, "cluster.yaml"))
cluster.to("json", os.path.join(tmpdir, "cluster.json"))

# cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.yaml"))
# assert cluster == cluster2
# cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.json"))
# assert cluster == cluster2
cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.yaml"))
assert cluster == cluster2
cluster2 = Cluster.from_file(os.path.join(tmpdir, "cluster.json"))
assert cluster == cluster2

with pytest.raises(ValueError):
cluster.to("bad_format")

0 comments on commit 7800edd

Please sign in to comment.