def test_in_tempdir(): my_cwd = getcwd() with in_tempdir() as tmpdir: _ = open("test.txt", "wt").write("some text") assert_true(isfile("test.txt")) assert_true(isfile(pjoin(tmpdir, "test.txt"))) assert_false(exists(tmpdir)) assert_equal(getcwd(), my_cwd)
def test_in_tempdir(): my_cwd = getcwd() with in_tempdir() as tmpdir: _ = open('test.txt', 'wt').write('some text') assert_true(isfile('test.txt')) assert_true(isfile(pjoin(tmpdir, 'test.txt'))) assert_false(exists(tmpdir)) assert_equal(getcwd(), my_cwd)
def test_in_tempdir(): my_cwd = getcwd() with in_tempdir() as tmpdir: _ = open('test.txt', 'wt').write('some text') assert_(isfile('test.txt')) assert_(isfile(pjoin(tmpdir, 'test.txt'))) assert_(not exists(tmpdir)) assert_equal(getcwd(), my_cwd)
def test_byte_gatts(): # Check that global "string" atts work like they did before py3k # unicode and general bytes confusion with in_tempdir(): filename = 'g_byte_atts.nc' f = netcdf_file(filename, 'w') f._attributes['holy'] = b'grail' f._attributes['witch'] = 'floats' f.close() f = netcdf_file(filename, 'r') assert_equal(f._attributes['holy'], b'grail') assert_equal(f._attributes['witch'], b'floats') f.close()
def test_open_append(): # open 'w' put one attr with in_tempdir(): filename = 'append_dat.nc' f = netcdf_file(filename, 'w') f._attributes['Kilroy'] = 'was here' f.close() # open again in 'a', read the att and and a new one f = netcdf_file(filename, 'a') assert_equal(f._attributes['Kilroy'], b'was here') f._attributes['naughty'] = b'Zoot' f.close() # open yet again in 'r' and check both atts f = netcdf_file(filename, 'r') assert_equal(f._attributes['Kilroy'], b'was here') assert_equal(f._attributes['naughty'], b'Zoot') f.close()