CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dataset_test.py
Go to the documentation of this file.
1 from dataset import *
2 
3 import unittest
4 import os
5 import shutil
6 
7 BASE_DIR = 'datasets'
8 
9 def create_dataset(name, number_of_files, basedir=BASE_DIR):
10  if not os.path.isdir(basedir):
11  os.mkdir(basedir)
12  old = os.getcwd()
13  os.chdir(basedir)
14  if os.path.isdir(name):
15  shutil.rmtree(name)
16  os.mkdir(name)
17  os.chdir(name)
18  for i in range(number_of_files):
19  os.system('touch file_{i:d}.root'.format(i=i))
20  os.chdir(old)
21 
22 class TestDataset(unittest.TestCase):
23 
24  def test_local(self):
25  n_files = 10
26  create_dataset('ds1', n_files)
27  ds1 = LocalDataset('/ds1', 'datasets', '.*root')
28  self.assertEqual( len(ds1.listOfGoodFiles()), n_files)
29  # shutil.rmtree('datasets')
30 
31  def test_eos(self):
32  ds1 = EOSDataset('/eos/cms/store/cmst3/user/cbern/EOSTests/ds1',
33  '.*root')
34  self.assertEqual(len(ds1.listOfGoodFiles()), 10)
35 
36  def test_eos_fail(self):
37  self.assertRaises( ValueError,
38  EOSDataset, 'not_existing_path', '.*root')
39  # should test that we fail when a plain file is provided
40  # instead ofa directory.. but eostools not set up for that yet.
41 
42 
43 if __name__ == '__main__':
44  import os
45  import sys
46  if not os.environ.get('CMSSW_BASE', False):
47  sys.exit(1)
48  unittest.main()
def create_dataset
Definition: dataset_test.py:9