Example #1
0
class TestFccswDataset(unittest.TestCase):
    def setUp(self):
        self.dataset = Dataset(dataset_name_fccsw,
                               dataset_pattern_fccsw,
                               cache=False,
                               xsection=1.8e-9)
        self.nfiles = 10
        self.ngoodfiles = 10
        self.nevents = 10

    def test_1_create(self):
        '''Test dataset creation'''
        self.assertEqual(len(self.dataset.all_files), self.nfiles)
        self.assertEqual(len(self.dataset.list_of_good_files()),
                         self.ngoodfiles)
        self.assertEqual(self.dataset.nfiles(), self.nfiles)
        self.assertEqual(self.dataset.ngoodfiles(), self.ngoodfiles)

    def test_2_cache(self):
        '''Test dataset reading from cache'''
        dataset = Dataset(dataset_name_fccsw, cache=cache)
        self.assertEqual(len(dataset.all_files), self.nfiles)
        self.assertEqual(len(dataset.list_of_good_files()), self.ngoodfiles)
        self.assertEqual(dataset.uid(), self.dataset.uid())

    #----------------------------------------------------------------------
    def test_3_nevents(self):
        """Test that the number of events is correct"""
        dataset = Dataset(dataset_name_fccsw, cache=cache)
        self.assertEqual(dataset.nevents(), 100)

    #----------------------------------------------------------------------
    def test_4_yaml(self):
        """Test that the yaml file can be written and read."""
        dataset = Dataset(dataset_name_fccsw, cache=cache)
        data_written = dataset.write_yaml()
        data_read = dataset._read_yaml()
        self.assertDictEqual(data_written, data_read)

    #----------------------------------------------------------------------
    def test_5_jobtype_fccsw(self):
        """test that the jobtype can be determined for fccsw"""
        dataset = Dataset(dataset_name_fccsw, cache=cache)
        self.assertEqual(dataset._jobtype, 'fccsw')

    #----------------------------------------------------------------------
    def test_6_update(self):
        """test that when something is changed, the unique id stays the same.
        """
        dataset = Dataset(dataset_name_fccsw, xsection=1, cache=True)
        self.assertEqual(dataset.uid(), self.dataset.uid())
        self.assertEqual(dataset.xsection(), 1)
        dataset = Dataset(dataset_name_fccsw, cache=True)
        self.assertEqual(dataset.xsection(), 1)
Example #2
0
 def test_6_update(self):
     """test that when something is changed, the unique id stays the same.
     """
     dataset = Dataset(dataset_name_fccsw, xsection=1, cache=True)
     self.assertEqual(dataset.uid(), self.dataset.uid())
     self.assertEqual(dataset.xsection(), 1)
     dataset = Dataset(dataset_name_fccsw, cache=True)
     self.assertEqual(dataset.xsection(), 1)
Example #3
0
class TestHeppyDataset(unittest.TestCase):
    
    def setUp(self):
        self.dataset = Dataset(dataset_name_heppy, dataset_pattern_heppy,
                               cache=False,
                               extract_info=True, 
                               cfg=cfg_name, xsection=1.8e-9)
        self.dataset.write()
        self.nfiles = 1
        self.ngoodfiles = 1
        self.nevents = 100

    def test_1_create(self):
        '''Test dataset creation'''
        self.assertEqual(len(self.dataset.all_files), self.nfiles)
        self.assertEqual(len(self.dataset.list_of_good_files()), self.ngoodfiles)
        self.assertEqual(self.dataset.nfiles(), self.nfiles)
        self.assertEqual(self.dataset.ngoodfiles(), self.ngoodfiles)

    def test_2_cache(self):
        '''Test dataset reading from cache'''
        dataset = Dataset(dataset_name_heppy, cache=True)
        self.assertEqual(len(dataset.all_files), self.nfiles)
        self.assertEqual(len(dataset.list_of_good_files()), self.ngoodfiles)
        self.assertEqual(dataset.uid(), self.dataset.uid())

    #----------------------------------------------------------------------
    def test_3_nevents(self):
        """Test that the number of events is correct"""
        dataset = Dataset(dataset_name_heppy, cache=True)
        self.assertEqual(dataset.nevents(), self.nevents)

    #----------------------------------------------------------------------
    def test_4_yaml(self):
        """Test that the yaml file can be written and read."""
        dataset = Dataset(dataset_name_heppy, dataset_pattern_heppy, 
                          cache=cache)
        data_written = dataset._write_yaml()
        data_read = dataset._read_yaml()
        self.assertDictEqual(data_written, data_read)
        
    #----------------------------------------------------------------------
    def test_5_jobtype_heppy(self):
        """test that the jobtype can be determined for heppy"""
        dataset = Dataset(dataset_name_heppy,
                          dataset_pattern_heppy, 
                          cache=False,
                          extract_info=True)
        self.assertEqual(dataset.jobtype(), 'heppy')
Example #4
0
 def test_2_cache(self):
     '''Test dataset reading from cache'''
     dataset = Dataset(dataset_name_heppy, cache=True)
     self.assertEqual(len(dataset.all_files), self.nfiles)
     self.assertEqual(len(dataset.list_of_good_files()), self.ngoodfiles)
     self.assertEqual(dataset.uid(), self.dataset.uid())
Example #5
0
class TestFccswDataset(unittest.TestCase):

    def setUp(self):
        self.dataset = Dataset(dataset_name_fccsw,
                               dataset_pattern_fccsw,
                               extract_info=True, 
                               cache=False,
                               xsection=1.8e-9)
        self.dataset.write()
        self.nfiles = 10
        self.ngoodfiles = 10
        self.nevents = 10

    def test_1_create(self):
        '''Test dataset creation'''
        self.assertEqual(len(self.dataset.all_files), self.nfiles)
        self.assertEqual(len(self.dataset.list_of_good_files()), self.ngoodfiles)
        self.assertEqual(self.dataset.nfiles(), self.nfiles)
        self.assertEqual(self.dataset.ngoodfiles(), self.ngoodfiles)

    def test_2_cache(self):
        '''Test dataset reading from cache'''
        dataset = Dataset(dataset_name_fccsw, cache=True)
        self.assertEqual(len(dataset.all_files), self.nfiles)
        self.assertEqual(len(dataset.list_of_good_files()), self.ngoodfiles)
        self.assertEqual(dataset.uid(), self.dataset.uid())

    #----------------------------------------------------------------------
    def test_3_nevents(self):
        """Test that the number of events is correct"""
        dataset = Dataset(dataset_name_fccsw, cache=True)
        self.assertEqual(dataset.nevents(), 100)

    #----------------------------------------------------------------------
    def test_4_yaml(self):
        """Test that the yaml file can be written and read."""
        dataset = Dataset(dataset_name_fccsw, cache=True)
        data_written = dataset._write_yaml()
        data_read = dataset._read_yaml()
        self.assertDictEqual(data_written, data_read)
        
    #----------------------------------------------------------------------
    def test_5_jobtype_fccsw(self):
        """test that the jobtype can be determined for fccsw"""
        dataset = Dataset(dataset_name_fccsw, cache=True)
        self.assertEqual(dataset.jobtype(), 'fccsw')

    #----------------------------------------------------------------------
    def test_6_update(self):
        """test that when something is changed, the unique id stays the same.
        """
        dataset = Dataset(dataset_name_fccsw, xsection=1, cache=True)
        self.assertEqual(dataset.uid(), self.dataset.uid())
        self.assertEqual(dataset.xsection(), 1)
        dataset.write()
        dataset = Dataset(dataset_name_fccsw, cache=True)
        self.assertEqual(dataset.xsection(), 1)
    
    def test_empty(self):
        """Check that an exception is raised when trying to
        read a dataset with no root file"""
        with self.assertRaises(ValueError):
            dataset = Dataset('papas/empty_dataset', '*.root', extract_info=True)
    
    def test_no_good_root_file(self):
        with self.assertRaises(ValueError):
            dataset = Dataset('papas/nogood_dataset', '*.root', extract_info=True)
        
    def test_no_yaml(self):
        with self.assertRaises(IOError):
            dataset = Dataset('papas/empty_dataset', '*.root', extract_info=False)