CMS 3D CMS Logo

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