1
"""
2
test_pipeline.py
3
"""
4 0
import sys
5 0
import os
6 0
import pytest
7 0
import shutil
8

9
# define location of input files for testing
10 0
mydir = os.path.dirname(os.path.abspath(__file__))
11

12
# import functions to aid testing
13 0
sys.path.append(os.path.join(os.path.dirname(__file__), 'helpers'))
14 0
from helper import *
15

16 0
from quanformer.pipeline import *
17

18
# -----------------------
19

20 0
def test_name_manager_pass():
21 0
    curr_dir, checked_infile, prefix, ext, no_path_infile = name_manager(
22
        os.path.join(mydir, 'data_tests', 'two_alkanes.smi'))
23 0
    assert prefix == 'two_alkanes'
24 0
    assert ext == '.smi'
25 0
    assert no_path_infile == 'two_alkanes.smi'
26

27 0
def test_name_manager_fail():
28 0
    with pytest.raises(FileNotFoundError):
29 0
        curr_dir, checked_infile, prefix, ext, no_path_infile = name_manager(
30
            os.path.join(mydir, 'data_tests', 'blah.sdf'))
31 0
    assert True
32

33 0
def test_setup_conformers():
34 0
    setup_conformers(os.path.join(mydir, 'data_tests', 'two_alkanes.smi'))
35

36
    # check pre-filtered file
37 0
    mols = read_mol(os.path.join(mydir, 'two_alkanes.sdf'), True)
38 0
    mol = next(mols)
39 0
    assert mol.NumConfs() == 9
40 0
    mol = next(mols)
41 0
    assert mol.NumConfs() == 3
42

43
    # check post-filtered file
44 0
    mols = read_mol(os.path.join(mydir, 'two_alkanes-200.sdf'), True)
45 0
    mol = next(mols)
46 0
    assert mol.NumConfs() == 3
47 0
    mol = next(mols)
48 0
    assert mol.NumConfs() == 3
49 0
    os.remove(os.path.join(mydir, 'two_alkanes.sdf'))
50 0
    os.remove(os.path.join(mydir, 'two_alkanes-200.sdf'))
51 0
    os.remove(os.path.join(mydir, 'numConfs.txt'))
52

53 0
def test_setup_conformers_ext():
54 0
    with pytest.raises(ValueError):
55 0
        setup_conformers(os.path.join(mydir, 'data_tests', 'methane_c2p.sdf'))
56 0
    assert True
57

58 0
def test_setup_calculations_true():
59 0
    setup_calculations(
60
        os.path.join(mydir, 'data_tests', 'methane_c2p.sdf'),
61
        'mp2',
62
        'def2-sv(p)',
63
        'spe')
64
    # check file byte size (this line should be updated if confs_to_psi changes)
65 0
    assert os.path.getsize(os.path.join('methane', '1', 'input.dat')) == 370
66 0
    shutil.rmtree('methane')
67

68 0
def test_setup_calculations_false():
69 0
    with pytest.raises(ValueError):
70 0
        setup_calculations(
71
            os.path.join(mydir, 'data_tests', 'methane_c2p.sdf'),
72
            'mp2',
73
            'def2-sv(p)',
74
            'blah')
75 0
    assert True
76

77 0
def test_process_results():
78 0
    process_results(os.path.join(mydir, 'data_tests', 'gbi-200.sdf'), 'opt')
79 0
    os.remove(os.path.join(os.getcwd(), 'gbi-210.sdf'))
80 0
    os.remove(os.path.join(os.getcwd(), 'gbi-220.sdf'))
81

82 0
def test_filter_results():
83 0
    filter_results(os.path.join(mydir, 'data_tests', 'gbi_prefilt.sdf'),
84
        os.path.join(mydir, 'data_tests', 'output.sdf'),
85
        'mp2','def2-SV(P)')
86 0
    os.remove(os.path.join(mydir, 'data_tests', 'output.sdf'))
87 0
    os.remove(os.path.join(os.getcwd(), 'numConfs.txt')) # don't use mydir here
88

89
# test manually without pytest
90 0
if 0:
91
    sys.path.insert(0, '/home/limvt/Documents/quanformer/quanformer')
92
    from pipeline import *
93
    test_name_manager_pass()
94
    test_name_manager_fail()
95
    test_setup_conformers()
96
    test_setup_calculations_true()
97
    test_setup_calculations_false()

Read our documentation on viewing source code .

Loading