示例#1
0
 def test_unknownarrayordertype(self):
     with tempdir() as dirname:
         dar = create_array(path=dirname, shape=(2,4), fill=0,
                            dtype='int64', overwrite=True)
         dar._update_arrayinfo({'arrayorder': 'X'})
         self.assertRaises(ValueError, numtypedescriptiontxt, dar)
         self.assertRaises(ValueError, Array, dirname)
示例#2
0
 def test_writejsondictincorrectinput(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         with self.assertRaises(TypeError):
             bd.write_jsondict('test1.json', 3)
         with self.assertRaises(TypeError):
             bd.write_jsondict('test1.json', 'a')
示例#3
0
 def test_readjsondictrequiredkeypresent(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         wd = {'a': 1, 'b': [1, 2, 3], 'c': 'k'}
         bd.write_jsondict('test1.json', wd)
         rd = bd.read_jsondict('test1.json', requiredkeys=('a', 'c'))
         self.assertDictEqual(wd, rd)
示例#4
0
 def test_openfile(self):
     with tempdir() as dirname:
         dar = create_array(path=dirname, shape=(0, 2), dtype='int64',
                            overwrite=True, accessmode='r+')
         with dar._datadir.open_file('notes.txt', 'a') as f:
             f.write('test\n')
         path = dar.path / 'notes.txt'
         self.assertEqual(path.exists(), True)
示例#5
0
 def test_pathexistsdonotoverwrite(self):
     with tempdir() as dirname:
         filepath = dirname / "test"
         open(filepath, 'w').close()
         self.assertRaises(OSError,
                           write_jsonfile,
                           path=filepath,
                           data={'a': 1})
示例#6
0
 def test_openfileprotectedfiles(self):
     with tempdir() as dirname:
         dar = create_array(path=dirname, shape=(0, 2), dtype='int64',
                            overwrite=True, accessmode='r+')
         for fn in dar._protectedfiles:
             with self.assertRaises(OSError):
                 with dar._datadir.open_file(fn, 'a') as f:
                     f.write('test\n')
示例#7
0
 def test_readjsondictrequiredkeynotpresent(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         wd = {'a': 1, 'b': [1, 2, 3], 'c': 'k'}
         bd.write_jsondict('test1.json', wd)
         self.assertRaises(ValueError,
                           bd.read_jsondict,
                           'test1.json',
                           requiredkeys=('a', 'd'))
示例#8
0
def create_testbasedatadir(filename='test.json', datadict=None):
    if datadict is None:
        datadict = {'a': 1}
    with tempdir() as dirname:
        bdddirname = Path(dirname) / 'data.bd'
        bdddirname.mkdir()
        bdd = DataDir(bdddirname)
        bdd._write_jsondict(filename, datadict)
        yield bdd
示例#9
0
 def test_protectedfiles(self):
     with tempdir() as dirname:
         bd = DataDir(dirname, protectedpaths=('test.dat', ))
         self.assertEqual(bd.protectedfiles, set(('test.dat', )))
示例#10
0
 def test_updatejsondictcorrect(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         bd.write_jsondict('test1.json', {'a': 1})
         bd.update_jsondict('test1.json', {'a': 2, 'b': 3})
示例#11
0
 def test_report(self):
     with tempdir(report=True) as td:
         pass  # see at least if this doesn't fail
示例#12
0
 def test_writejsondictcorrectinput(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         bd.write_jsondict('test1.json', {'a': 1})
示例#13
0
 def test_keep(self):
     with tempdir(keep=True) as td:
         pass
     self.assertTrue(td.exists())
     shutil.rmtree(td)
示例#14
0
 def test_isdeleted(self):
     with tempdir() as td:
         pass
     self.assertFalse(td.exists())
示例#15
0
 def test_writetxtoverwrite(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         bd.write_txt('test1.txt', 'hello')
         bd.write_txt('test1.txt', 'hello', overwrite=True)
示例#16
0
 def test_writetxt(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         bd.write_txt('test1.txt', 'hello')
         self.assertEqual(bd.read_txt('test1.txt'), 'hello')
示例#17
0
 def test_readjsondictnotdict(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         bd.write_jsonfile('test1.json', [1, 2, 3])
         self.assertRaises(TypeError, bd.read_jsondict, 'test1.json')
示例#18
0
 def test_deletefiles(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         bd.write_txt('test1.txt', 'hello')
         bd.write_txt('test2.txt', 'hello')
         bd.delete_files(('test1.txt', 'test2.txt', 'test3.txt'))
示例#19
0
 def test_deleteprotectedfile(self):
     with tempdir() as dirname:
         bd = DataDir(dirname, protectedpaths=('test.dat', ))
         self.assertRaises(OSError, bd.delete_files, (('test.dat', )))
示例#20
0
 def test_pathexistsnotoverwrite(self):
     with tempdir() as dirname:
         self.assertRaises(OSError, create_datadir, dirname)
示例#21
0
 def test_writetxtdonotoverwrite(self):
     with tempdir() as dirname:
         bd = DataDir(dirname)
         bd.write_txt('test1.txt', 'hello')
         self.assertRaises(OSError, bd._write_txt, 'test1.txt', 'hello')
示例#22
0
 def test_pathexistsoverwrite(self):
     with tempdir() as dirname:
         create_datadir(dirname, overwrite=True)
示例#23
0
 def test_futurewarningdeprecation(self):
     with tempdir() as dirname:
         self.assertWarns(FutureWarning, create_basedatadir, dirname, True)
示例#24
0
 def test_ispath(self):
     with tempdir() as td:
         self.assertIsInstance(td, Path)
         self.assertTrue(td.exists())
         self.assertTrue(td.is_dir())