class TestResults(TestCase): def setUp(self): TestCase.setUp(self) # Results 1 self.ops1 = Options(name='test1') self.ops1.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) self.ops1.detectors['det2'] = TimeDetector() self.ops1.detectors['det3'] = ElectronFractionDetector() results1 = {} results1['det1'] = PhotonIntensityResult() results1['det2'] = TimeResult() results1['det3'] = ElectronFractionResult() # Results 2 ops2 = Options(name='test2') ops2.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) results2 = {} results2['det1'] = PhotonIntensityResult() # Base options self.ops = Options(name='base') # Sequence list_results = [(self.ops1, results1), (ops2, results2)] self.results = Results(self.ops, list_results) def tearDown(self): TestCase.tearDown(self) def test__len__(self): self.assertEqual(2, len(self.results)) def test__repr__(self): self.assertEqual('<Results(2 results)>', repr(self.results)) def test__getitem__(self): self.assertEqual('test1', self.results[0].options.name) self.assertEqual('test2', self.results[1].options.name) self.assertRaises(IndexError, self.results.__getitem__, 2) def testreadwrite(self): with tempfile.NamedTemporaryFile() as f: self.results.write(f.name) obj = Results.read(f.name) self.assertEqual(2, len(obj)) self.assertEqual('test1', obj[0].options.name) self.assertEqual('test2', obj[1].options.name) self.assertIn('det1', obj[0]) self.assertIn('det2', obj[0]) self.assertIn('det3', obj[0]) self.assertIn('det1', obj[1])
def setUp(self): TestCase.setUp(self) # Results 1 self.ops1 = Options(name='test1') self.ops1.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) self.ops1.detectors['det2'] = TimeDetector() self.ops1.detectors['det3'] = ElectronFractionDetector() results1 = {} results1['det1'] = PhotonIntensityResult() results1['det2'] = TimeResult() results1['det3'] = ElectronFractionResult() # Results 2 ops2 = Options(name='test2') ops2.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) results2 = {} results2['det1'] = PhotonIntensityResult() # Base options self.ops = Options(name='base') # Sequence list_results = [(self.ops1, results1), (ops2, results2)] self.results = Results(self.ops, list_results)
def testappend(self): with tempfile.NamedTemporaryFile() as f: self.obj.write(f.name) # Append ops3 = Options(name='test3') newobj = Results(self.obj.options, [(ops3, {})]) append(newobj, f.name) obj = Results.read(f.name) self.assertEqual(3, len(obj))
class TestModule(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) ops1 = Options(name='test1') ops1.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) ops1.detectors['det2'] = TimeDetector() ops1.detectors['det3'] = ElectronFractionDetector() results1 = {} results1['det1'] = PhotonIntensityResult() results1['det2'] = TimeResult() results1['det3'] = ElectronFractionResult() ops2 = Options(name='test2') ops2.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) results2 = {} results2['det1'] = PhotonIntensityResult() self.obj = Results(Options(name='base'), [(ops1, results1), (ops2, results2)]) def tearDown(self): unittest.TestCase.tearDown(self) def testappend(self): with tempfile.NamedTemporaryFile() as f: self.obj.write(f.name) # Append ops3 = Options(name='test3') newobj = Results(self.obj.options, [(ops3, {})]) append(newobj, f.name) obj = Results.read(f.name) self.assertEqual(3, len(obj))
def testreadwrite(self): with tempfile.NamedTemporaryFile() as f: self.results.write(f.name) obj = Results.read(f.name) self.assertEqual(2, len(obj)) self.assertEqual('test1', obj[0].options.name) self.assertEqual('test2', obj[1].options.name) self.assertIn('det1', obj[0]) self.assertIn('det2', obj[0]) self.assertIn('det3', obj[0]) self.assertIn('det1', obj[1])
def setUp(self): unittest.TestCase.setUp(self) ops1 = Options(name='test1') ops1.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) ops1.detectors['det2'] = TimeDetector() ops1.detectors['det3'] = ElectronFractionDetector() results1 = {} results1['det1'] = PhotonIntensityResult() results1['det2'] = TimeResult() results1['det3'] = ElectronFractionResult() ops2 = Options(name='test2') ops2.detectors['det1'] = PhotonIntensityDetector((0, 1), (0, 1)) results2 = {} results2['det1'] = PhotonIntensityResult() self.obj = Results(Options(name='base'), [(ops1, results1), (ops2, results2)])
def _validate(self, filepath): Results.read(filepath)
def _import(self, options, dirpath, *args, **kwargs): filepath = os.path.join(dirpath, options.name + '.h5') return Results.read(filepath)[0]