Changeset efa05d7 in flex_extract.git


Ignore:
Timestamp:
Sep 2, 2018, 3:05:06 PM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
308e144
Parents:
97e09f4
Message:

added more testcases

Location:
python
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • python/pythontest/.cache/v/cache/lastfailed

    r97e09f4 refa05d7  
    11{
    22  "TestTools.py": true,
     3  "TestTools.py::TestTools::()::test_failany_silent_remove": true,
    34  "TestTools.py::TestTools::test_init128": true,
    45  "TestTools.py::TestTools::test_to_param_id": true
  • python/pythontest/TestTools.py

    r97e09f4 refa05d7  
    77import pipes
    88import pytest
     9from unittest.mock import patch
    910
    1011sys.path.append('../')
    1112import _config
    12 from tools import (init128, to_param_id, my_error, read_ecenv,
    13                    get_cmdline_arguments, submit_job_to_ecserver,
    14                    put_file_to_ecserver)
     13from tools import (get_cmdline_arguments, read_ecenv, clean_up, my_error,
     14                   normal_exit, product, silent_remove, init128, to_param_id,
     15                   get_list_as_string, make_dir, put_file_to_ecserver,
     16                   submit_job_to_ecserver)
    1517
    1618
     
    108110        assert True
    109111
    110     def test_silent_remove(self):
    111         assert True
     112    def test_success_silent_remove(self, capfd):
     113        testfile = 'testfile.test'
     114        open(testfile, 'w').close()
     115        silent_remove(testfile)
     116        out, err = capfd.readouterr()
     117        assert os.path.isfile(testfile) == False
     118        assert out == ''
     119
     120    def test_failnotexist_silent_remove(self, capfd):
     121        testfile = 'testfile.test'
     122        silent_remove(testfile)
     123        out, err = capfd.readouterr()
     124        assert os.path.isfile(testfile) == False
     125        assert out == ''
     126
     127    @patch(silent_remove)
     128    def test_failany_silent_remove(self, mock_silent_remove):
     129        testfile = 'testfileany.test'
     130        mock_silent_remove.side_effect = OSError
     131        with pytest.raises(OSError) as pytest_wrapped_e:
     132            silent_remove(testfile)
     133        #out, err = capfd.readouterr()
     134        #assert os.path.isfile(testfile) == False
     135        #assert out == ''
    112136
    113137    def test_get_list_as_string(self):
    114138        assert True
    115139
    116     def test_make_dir(self):
    117         assert True
     140    def test_warningexist_make_dir(self, capfd):
     141        testdir = 'TestData'
     142        make_dir(testdir)
     143        out, err = capfd.readouterr()
     144        assert out.strip() == 'WARNING: Directory {0} already exists!'.format(testdir)
     145
     146    def test_failany_make_dir(self):
     147        testdir = '/test' # force a permission denied error
     148        with pytest.raises(OSError) as pytest_wrapped_e:
     149            make_dir(testdir)
     150        assert pytest_wrapped_e.type == OSError
     151
     152    def test_success_make_dir(self):
     153        testdir = 'testing_mkdir'
     154        make_dir(testdir)
     155        assert os.path.exists(testdir) == True
     156        os.rmdir(testdir)
    118157
    119158    def test_fail_put_file_to_ecserver(self):
  • python/tools.py

    r97e09f4 refa05d7  
    316316    '''
    317317    @Description:
    318         If "filename" exists , it is removed.
     318        Remove file if it exists.
    319319        The function does not fail if the file does not exist.
    320320
     
    329329        os.remove(filename)
    330330    except OSError as e:
    331         # this would be "except OSError, e:" before Python 2.6
    332331        if e.errno != errno.ENOENT:
    333332            # errno.ENOENT  =  no such file or directory
     
    427426    @Input:
    428427        directory: string
    429             The directory path which should be created.
     428            The directory name including the path which should be created.
    430429
    431430    @Return:
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG