File: test_settings.py

package info (click to toggle)
python-emmet-core 0.84.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 77,220 kB
  • sloc: python: 16,355; makefile: 30
file content (58 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import os
from pathlib import PosixPath
from random import random

import pytest

from monty.serialization import dumpfn, loadfn
from monty.tempfile import ScratchDir

from emmet.core.settings import EmmetSettings


def test_default_config_path(tmp_path: PosixPath):
    """Make sure the default config path works"""

    rand_symprec = random()
    with open(tmp_path / "temp_config.json", "w") as f:
        json.dump({"SYMPREC": rand_symprec}, f)

    os.environ["EMMET_CONFIG_FILE"] = str(tmp_path.resolve() / "temp_config.json")
    test_config = EmmetSettings()

    assert test_config.SYMPREC == rand_symprec


def test_allow_extra_fields(tmp_path: PosixPath):
    """Makes sure emmet config can be subclassed without loading issues"""

    with open(tmp_path / "temp_config.json", "w") as f:
        json.dump({"sub_class_prop": True}, f)

    os.environ["EMMET_CONFIG_FILE"] = str(tmp_path.resolve() / "temp_config.json")

    EmmetSettings()


def test_from_url():
    """Makes sure loading from a URL Works"""

    os.environ[
        "EMMET_CONFIG_FILE"
    ] = "https://raw.githubusercontent.com/materialsproject/emmet/master/test_files/test_settings.json"

    test_config = EmmetSettings()

    assert test_config.ANGLE_TOL == 1.0


@pytest.mark.skip("'MPRelaxSet' has no attribute 'config_dict'")
def test_seriallization():
    test_config = EmmetSettings()

    with ScratchDir("."):
        dumpfn(test_config, "test.json")
        reload_config = loadfn("test.json")

        assert isinstance(reload_config, EmmetSettings)