CMS 3D CMS Logo

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('/EOSTests/ds1',
33  '/eos/cms/store/cmst3/user/cbern',
34  '.*root')
35  self.assertEqual(len(ds1.listOfGoodFiles()), 10)
36 
37  def test_eos_fail(self):
38  self.assertRaises( ValueError,
39  EOSDataset,
40  'not_existing_basedir',
41  'not_exiting_dataset',
42  '.*root')
43  # should test that we fail when a plain file is provided
44  # instead of a directory.. but eostools not set up for that yet.
45 
46 
47 if __name__ == '__main__':
48  import os
49  import sys
50  if not os.environ.get('CMSSW_BASE', False):
51  sys.exit(1)
52  unittest.main()
def create_dataset(name, number_of_files, basedir=BASE_DIR)
Definition: dataset_test.py:9