#! /usr/bin/env python
#
# Tests for dakota_utils.file.
#
# Call with:
#   $ nosetests -sv
#
# Mark Piper (mark.piper@colorado.edu)

from nose.tools import *
import os
import tempfile
import shutil
from dakota_utils.file import *

def setup_module():
    print('File tests:')
    os.environ['_test_tmp_dir'] = tempfile.mkdtemp()

def teardown_module():
    shutil.rmtree(os.environ['_test_tmp_dir'])

@raises(TypeError)
def test_remove_zero_arguments():
    '''
    Tests for no input parameter to remove().
    '''
    remove()

@raises(TypeError)
def test_remove_file_zero_arguments():
    '''
    Tests for no input parameter to remove_file().
    '''
    remove_file()

@raises(TypeError)
def test_remove_directory_zero_arguments():
    '''
    Tests for no input parameter to remove_directory().
    '''
    remove_directory()

@raises(TypeError)
def test_touch_zero_arguments():
    '''
    Tests for no input parameter to touch().
    '''
    touch()


@@ -948,12 +948,1978 @@
    touch()%0A%0A
+def test_remove_file_does_not_exist():%0A    '''%0A    Tests deleting a nonexistent file with remove_file().%0A    '''    %0A    fname = 'vwbwguv00240cnwuncdsv'%0A    remove_file(os.path.join(os.environ%5B'_test_tmp_dir'%5D, fname))%0A%0Adef test_remove_directory_does_not_exist():%0A    '''%0A    Tests deleting a nonexistent directory with remove_directory().%0A    '''    %0A    dname = 'vwbwguv00240cnwuncdsv'%0A    remove_directory(os.path.join(os.environ%5B'_test_tmp_dir'%5D, dname))%0A%0Adef test_remove_does_not_exist():%0A    '''%0A    Tests deleting a nonexistent file or directory with remove().%0A    '''    %0A    name = 'vwbwguv00240cnwuncdsv'%0A    remove(os.path.join(os.environ%5B'_test_tmp_dir'%5D, name))%0A%0Adef test_remove_file():%0A    '''%0A    Tests that remove_file() deletes a file.%0A    '''    %0A    bname = 'delete_me'%0A    fname = os.path.join(os.environ%5B'_test_tmp_dir'%5D, bname)%0A    touch(fname)%0A    remove_file(fname)%0A    assert_false(os.path.exists(fname))%0A%0Adef test_remove_directory():%0A    '''%0A    Tests that remove_directory() deletes a directory.%0A    '''    %0A    bname = 'delete_me'%0A    dname = os.path.join(os.environ%5B'_test_tmp_dir'%5D, bname)%0A    os.mkdir(dname)%0A    remove_directory(dname)%0A    assert_false(os.path.exists(dname))%0A%0Adef test_remove_a_file():%0A    '''%0A    Tests that remove() deletes a file. (Uses touch)%0A    '''%0A    bname = 'delete_me'%0A    fname = os.path.join(os.environ%5B'_test_tmp_dir'%5D, bname)%0A    touch(fname)%0A    remove(fname)%0A    assert_false(os.path.exists(fname))%0A%0Adef test_remove_a_directory():%0A    '''%0A    Tests that remove() deletes a directory.%0A    '''    %0A    bname = 'delete_me'%0A    dname = os.path.join(os.environ%5B'_test_tmp_dir'%5D, bname)%0A    os.mkdir(dname)%0A    remove(dname)%0A    assert_false(os.path.exists(dname))%0A%0Adef test_touch():%0A    '''%0A    Tests that touch() makes a file. (Uses remove)%0A    '''%0A    bname = 'a_file'%0A    fname = os.path.join(os.environ%5B'_test_tmp_dir'%5D, bname)%0A    touch(fname)%0A    assert_true(os.path.exists(fname))%0A    remove(fname)%0A

Add more unit tests for file module