# CREATED: 10/15/16 7:52 PM by Justin Salamon <justin.salamon@nyu.edu>

'''
Tests for functions in util.py
'''

from scaper.util import _close_temp_files
from scaper.util import _set_temp_logging_level
import tempfile
import os
import logging


def test_close_temp_files():
    '''
    Create a bunch of temp files and then make sure they've been closed and
    deleted.

    '''
    tmpfiles = []

    with _close_temp_files(tmpfiles):
        for _ in range(5):
            tmpfiles.append(
                tempfile.NamedTemporaryFile(suffix='.wav', delete=True))

    for tf in tmpfiles:
        assert tf.file.closed
        assert not os.path.isfile(tf.name)


def test_set_temp_logging_level():
    '''
    Ensure temp logging level is set as expected


    '''
    logger = logging.getLogger()
    logger.setLevel('DEBUG')
    with _set_temp_logging_level('CRITICAL'):
        assert logging.getLevelName(logger.level) == 'CRITICAL'
    assert logging.getLevelName(logger.level) == 'DEBUG'

@@ -195,16 +195,111 @@
 g_level%0A
+from scaper.util import _validate_folder_path%0Afrom scaper.scaper_exceptions import ScaperError%0A
 import t
@@ -331,16 +331,44 @@
 logging%0A
+import pytest%0Aimport shutil%0A
 %0A%0Adef te
@@ -875,17 +875,16 @@
 pected%0A%0A
-%0A
     '''%0A
@@ -1055,16 +1055,16 @@
 ITICAL'%0A
-
     asse
@@ -1112,8 +1112,420 @@
 'DEBUG'%0A
+%0A%0Adef test_validate_folder_path():%0A    '''%0A    Make sure invalid folder paths are caught%0A%0A    '''%0A    # bad folder path%0A    pytest.raises(ScaperError, _validate_folder_path,%0A                  '/path/to/invalid/folder/')%0A%0A    # good folder path should raise no error%0A    # make temp folder%0A    tmpdir = tempfile.mkdtemp()%0A    # validate%0A    _validate_folder_path(tmpdir)%0A    # remove it%0A    shutil.rmtree(tmpdir)%0A

Implement test_validate_folder_path