source: flex_extract.git/source/pythontest/TestInstall.py @ 0aaeb04

ctbtodev
Last change on this file since 0aaeb04 was 0aaeb04, checked in by Anne Philipp <anne.philipp@…>, 5 years ago

added writing of compilejob and ECMWF_ENV via templates and added tests

  • Property mode set to 100644
File size: 5.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4
5import sys
6import os
7import inspect
8import pytest
9
10sys.path.append('../python')
11import _config
12import install
13from mods.tools import make_dir, silent_remove
14
15
16class TestTools():
17    '''
18    '''
19
20
21    #    - main
22    #    - get_install_cmdline_arguments
23    #    - install_via_gateway
24    #!    - mk_tarball
25    #!    - un_tarball
26    #!    - mk_env_vars
27    #    - mk_compilejob
28    #    - mk_job_template
29    #    - delete_convert_build
30    #    - make_convert_build
31
32    def test_mk_tarball_local(self):
33        import tarfile
34
35        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
36
37        # list comparison files for tarball content
38        tar_test_dir = os.path.join(_config.PATH_TEST_DIR +
39                                    os.path.sep + 'TestInstallTar')
40        tar_test_file = os.path.join(tar_test_dir,
41                                     'flex_extract_v7.1_local.tar')
42        with tarfile.open(tar_test_file, 'r') as tar_handle:
43            comparison_list = tar_handle.getnames()
44
45        # create test tarball and list its content files
46        tarballname = _config.FLEXEXTRACT_DIRNAME + '_localtest.tar'
47        install.mk_tarball(ecd + tarballname, 'local')
48        with tarfile.open(ecd + tarballname, 'r') as tar_handle:
49            tar_content_list = tar_handle.getnames()
50
51        # remove test tar file from flex_extract directory
52        os.remove(ecd + tarballname)
53
54        # test if comparison filelist is equal to the
55        # filelist of tarball content
56        assert sorted(comparison_list) == sorted(tar_content_list)
57
58    def test_mk_tarball_ecgate(self):
59        import tarfile
60
61        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
62
63        # list comparison files for tarball content
64        tar_test_dir = os.path.join(_config.PATH_TEST_DIR +
65                                    os.path.sep + 'TestInstallTar')
66        tar_test_file = os.path.join(tar_test_dir,
67                                     'flex_extract_v7.1_ecgate.tar')
68        with tarfile.open(tar_test_file, 'r') as tar_handle:
69            comparison_list = tar_handle.getnames()
70
71        # create test tarball and list its content files
72        tarballname = _config.FLEXEXTRACT_DIRNAME + '_ecgatetest.tar'
73        install.mk_tarball(ecd + tarballname, 'ecgate')
74        with tarfile.open(ecd + tarballname, 'r') as tar_handle:
75            tar_content_list = tar_handle.getnames()
76
77        # remove test tar file from flex_extract directory
78        os.remove(ecd + tarballname)
79
80        # test if comparison filelist is equal to the
81        # filelist of tarball content
82        assert sorted(comparison_list) == sorted(tar_content_list)
83
84    def test_un_tarball(self):
85        import tarfile
86        import shutil
87
88        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
89
90        # list comparison files for tarball content
91        tar_test_dir = os.path.join(_config.PATH_TEST_DIR +
92                                        os.path.sep + 'TestInstallTar')
93        tar_test_fedir = os.path.join(tar_test_dir, 'flex_extract_v7.1_ecgate')
94        comparison_list = []
95        for path, subdirs, files in os.walk(tar_test_fedir):
96            for name in files:
97                if 'tar' not in name:
98                    comparison_list.append(os.path.relpath(
99                        os.path.join(path, name), tar_test_fedir))
100
101        # untar in test directory
102        test_dir = os.path.join(tar_test_dir, 'test_untar')
103        make_dir(test_dir)
104        os.chdir(test_dir)
105        tarballname = _config.FLEXEXTRACT_DIRNAME + '_ecgate.tar'
106        install.un_tarball(os.path.join(tar_test_dir, tarballname))
107        tarfiles_list = []
108        for path, subdirs, files in os.walk(test_dir):
109            for name in files:
110                tarfiles_list.append(os.path.relpath(
111                    os.path.join(path, name), test_dir))
112
113        # test for equality
114        assert sorted(tarfiles_list) == sorted(comparison_list)
115
116        # clean up temp test dir
117        shutil.rmtree(test_dir)
118
119    def test_mk_env_vars(self):
120        import filecmp
121
122        # comparison file
123        testfile = os.path.join(_config.PATH_TEST_DIR,'TestData',
124                                'ECMWF_ENV.test')
125
126        # create test ECMWF_ENV file
127        install.mk_env_vars('testuser',
128                            'testgroup',
129                            'gateway.test.ac.at',
130                            'user@destination')
131
132        assert filecmp.cmp(testfile, _config.PATH_ECMWF_ENV, shallow=False)
133
134        # delte test file
135        silent_remove(_config.PATH_ECMWF_ENV)
136
137    def test_mk_compilejob(self):
138        import filecmp
139
140        # comparison file
141        testfile = os.path.join(_config.PATH_TEST_DIR,'TestData',
142                                    'compilejob.test')
143
144        # create
145        install.mk_compilejob('Makefile.TEST',
146                              '',
147                              'testuser',
148                              'testgroup',
149                              'fp_root_test_path')
150
151        finalfile = os.path.join(_config.PATH_JOBSCRIPTS,
152                              _config.FILE_INSTALL_COMPILEJOB)
153        assert filecmp.cmp(testfile, finalfile, shallow=False)
154
155        # delete test file
156        silent_remove(finalfile)
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG