from __future__ import unicode_literals

from nose.tools import *
import os
import time
from dit.utils import cd, named_tempfile, tempdir

def test_cd():
    with cd('/'):
        assert_equal(os.getcwd(), '/')

def test_named_tempfile():
    name = None
    with named_tempfile() as tempfile:
        name = tempfile.name
        assert_true(os.path.isfile(name))
        tempfile.write('hello'.encode('ascii'))
        tempfile.close()
        assert_true(os.path.isfile(name))
    assert_false(os.path.isfile(name))

def test_tempdir():
    name = None
    with tempdir() as tmpdir:
        assert_true(os.path.isdir(tmpdir))
    assert_false(os.path.isdir(tmpdir))

from __future__ import unicode_literals

from nose.tools import *
import os
import time
from dit.utils import cd, named_tempfile, tempdir

def test_cd():
    with cd('/'):
        assert_equal(os.getcwd(), '/')

def test_named_tempfile1():
    name = None
    with named_tempfile() as tempfile:
        name = tempfile.name
        assert_true(os.path.isfile(name))
        tempfile.write('hello'.encode('ascii'))
        tempfile.close()
        assert_true(os.path.isfile(name))
    assert_false(os.path.isfile(name))

def test_named_tempfile2():
    name = None
    # The specification of delete=True should be ignored.
    with named_tempfile(delete=True) as tempfile:
        name = tempfile.name
        assert_true(os.path.isfile(name))
        tempfile.write('hello'.encode('ascii'))
        tempfile.close()
        assert_true(os.path.isfile(name))
    assert_false(os.path.isfile(name))


def test_tempdir():
    name = None
    with tempdir() as tmpdir:
        assert_true(os.path.isdir(tmpdir))
    assert_false(os.path.isdir(tmpdir))

Add test to verify that named_tempfile() overrides the `delete` parameter.
Add test to verify that named_tempfile() overrides the `delete` parameter.

  from __future__ import unicode_literals
  
  from nose.tools import *
  import os
  import time
  from dit.utils import cd, named_tempfile, tempdir
  
  def test_cd():
      with cd('/'):
          assert_equal(os.getcwd(), '/')
  
- def test_named_tempfile():
+ def test_named_tempfile1():
      name = None
      with named_tempfile() as tempfile:
          name = tempfile.name
          assert_true(os.path.isfile(name))
          tempfile.write('hello'.encode('ascii'))
          tempfile.close()
          assert_true(os.path.isfile(name))
      assert_false(os.path.isfile(name))
  
+ def test_named_tempfile2():
+     name = None
+     # The specification of delete=True should be ignored.
+     with named_tempfile(delete=True) as tempfile:
+         name = tempfile.name
+         assert_true(os.path.isfile(name))
+         tempfile.write('hello'.encode('ascii'))
+         tempfile.close()
+         assert_true(os.path.isfile(name))
+     assert_false(os.path.isfile(name))
+ 
+ 
  def test_tempdir():
      name = None
      with tempdir() as tmpdir:
          assert_true(os.path.isdir(tmpdir))
      assert_false(os.path.isdir(tmpdir))
  
Add test to verify that named_tempfile() overrides the `delete` parameter.
## Code Before:
from __future__ import unicode_literals

from nose.tools import *
import os
import time
from dit.utils import cd, named_tempfile, tempdir

def test_cd():
    with cd('/'):
        assert_equal(os.getcwd(), '/')

def test_named_tempfile():
    name = None
    with named_tempfile() as tempfile:
        name = tempfile.name
        assert_true(os.path.isfile(name))
        tempfile.write('hello'.encode('ascii'))
        tempfile.close()
        assert_true(os.path.isfile(name))
    assert_false(os.path.isfile(name))

def test_tempdir():
    name = None
    with tempdir() as tmpdir:
        assert_true(os.path.isdir(tmpdir))
    assert_false(os.path.isdir(tmpdir))

## Instruction:
Add test to verify that named_tempfile() overrides the `delete` parameter.
## Code After:
from __future__ import unicode_literals

from nose.tools import *
import os
import time
from dit.utils import cd, named_tempfile, tempdir

def test_cd():
    with cd('/'):
        assert_equal(os.getcwd(), '/')

def test_named_tempfile1():
    name = None
    with named_tempfile() as tempfile:
        name = tempfile.name
        assert_true(os.path.isfile(name))
        tempfile.write('hello'.encode('ascii'))
        tempfile.close()
        assert_true(os.path.isfile(name))
    assert_false(os.path.isfile(name))

def test_named_tempfile2():
    name = None
    # The specification of delete=True should be ignored.
    with named_tempfile(delete=True) as tempfile:
        name = tempfile.name
        assert_true(os.path.isfile(name))
        tempfile.write('hello'.encode('ascii'))
        tempfile.close()
        assert_true(os.path.isfile(name))
    assert_false(os.path.isfile(name))


def test_tempdir():
    name = None
    with tempdir() as tmpdir:
        assert_true(os.path.isdir(tmpdir))
    assert_false(os.path.isdir(tmpdir))
