-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_Calculator.py
67 lines (45 loc) · 1.67 KB
/
test_Calculator.py
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
59
60
61
62
63
64
65
66
67
###########################################################
#
# pytest runner for the Calculator class
#
###########################################################
import pytest
import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath)
from Calculator import Calculator
from Structure import Structure
from PluginBase import PluginBase
from CalcPlugin_ASE import CalcPlugin_ASE
test_file = "diamond.pdb"
dna_file = "dna.pdb"
# Generate Structure objects
diamond = Structure(file=test_file)
dna = Structure(file=dna_file)
def test_calculator_default():
calc = Calculator()
assert calc.parameters == {}
assert calc.DEFAULT_ENGINE['XRD'] == 'ASE'
assert calc.DEFAULT_ENGINE['SANS'] == 'ASE'
assert calc.activePlugin == None
calc.loadPlugin(engine="ASE")
assert isinstance(calc.activePlugin, CalcPlugin_ASE) == True
def test_calculator_arg_structure():
calc = Calculator(structure=diamond, wavelength=1.2)
assert calc.parameters['structure'] == diamond
assert calc.parameters['wavelength'] == 1.2
assert calc.activePlugin == None
calc.loadPlugin(engine="ASE")
assert isinstance(calc.activePlugin, CalcPlugin_ASE) == True
def test_override_arguments():
calc = Calculator(structure=diamond, wavelength=1.5)
calc.structure = dna
calc.wavelength = 1.1
assert calc.parameters['structure'] == dna
assert calc.parameters['wavelength'] == 1.1
assert calc.structure == dna
assert calc.wavelength == 1.1
def test_calculator_load_plugin():
calc = Calculator(structure=diamond, wavelength=1.5)
with pytest.raises(ModuleNotFoundError):
calc.loadPlugin(engine="boop")