def setUp(self): """ Note: This actually requires quite a lot of things to be working to run (get_dats does quite a lot of work) Returns: """ print('running setup') # SetUp before tests helpers.clear_outputs(output_dir) self.dats = get_dats([717, 719, 720, 723, 724, 725], exp2hdf=Testing_Exp2HDF, overwrite=True)
class TestDatAttributeWithData(TestCase): helpers.clear_outputs(output_dir) dat = helpers.init_testing_dat(9111, output_dir) T: transition.Transition = Testing_Transition(dat) def test_get_data(self): data = self.T.get_data('x') print(data) expected = [-276.57, -276.56177, -276.55353] self.assertTrue(np.allclose(expected, data[:3])) def test_set_data(self): data = np.linspace(0, 100, 1000) self.T.set_data('test_data', data) get_data = self.T.get_data('test_data') self.assertTrue(np.allclose(data, get_data)) def test_specific_data_descriptors(self): sdd = self.T.specific_data_descriptors_keys print(sdd) self.assertIsInstance(sdd['test_data'], DataDescriptor) def test_set_data_descriptor(self): orig = self.T.get_descriptor('x') new = copy.copy(orig) new.multiply = 2.0 self.T.set_data_descriptor(new, 'test_descriptor') new_get = self.T.get_descriptor('test_descriptor') self.assertEqual(new, new_get) def test_get_descriptor(self): desc = self.T.get_descriptor('x') print(desc) expected = DataDescriptor('/Experiment Copy/x_array') self.assertEqual(expected, desc)
class TestEntropy(TestCase): helpers.clear_outputs(output_dir) dat = helpers.init_testing_dat(9111, output_directory=output_dir) E = Entropy(dat) def test_get_default_params(self): default_pars = self.E.get_default_params() self.assertEqual(DEFAULT_PARAMS, default_pars) self.assertTrue(True) def test_get_non_default_params(self): pars = self.E.get_default_params(self.E.x, self.E.data[0:5]) self.assertTrue(np.all([isinstance(p, lm.Parameters) for p in pars])) def test_get_default_func(self): self.assertEqual(entropy_nik_shape, self.E.get_default_func()) def test_get_avg_entropy(self): fit = self.E.avg_fit print(fit.best_values) expected = (0.7149, 0.0736, -0.969, 16.384) bv = fit.best_values self.assertTrue( np.allclose(expected, (bv.dS, bv.dT, bv.mid, bv.theta), rtol=0.01, atol=0.01))
class TestExpConfigGroupDatAttribute(TestCase): helpers.clear_outputs(output_dir) exp2hdf = helpers.get_testing_Exp2HDF(dat_dir=dat_dir, output_dir=output_dir)(9111) builder = DatHDFBuilder(exp2hdf, init_level='min') builder.create_hdf() builder.copy_exp_data() builder.init_DatHDF() builder.init_base_attrs() dat = builder.dat E = Testing_ExpConfigDatAttribute(dat, exp_config=ExpConfig(9111)) def setUp(self): """Runs before every test""" pass def tearDown(self): """Runs after every test""" pass def test__set_default_data_descriptors(self): self.E._set_default_data_descriptors() with h5py.File(self.E.hdf.hdf_path, 'r') as f: group = f.get(self.E.group_name + '/Default DataDescriptors') keys = group.keys() self.assertTrue( {'cscurrent', 'cscurrent_2d', 'x_array', 'y_array'} - set(keys) == set()) # Check expected keys are there def test__initialize_minimum(self): self.E.initialize_minimum() self.assertTrue(self.E.initialized) def test__set_sweeplog_subs(self): self.E._set_sweeplog_subs() with h5py.File(self.E.hdf.hdf_path, 'r') as f: group = f.get(self.E.group_name) subs = HDU.get_attr(group, 'sweeplog_substitutions', None) self.assertEqual(subs, {'FastDAC 1': 'FastDAC'}) def test_get_sweeplogs(self): sweeplogs = self.E.get_sweeplogs() self.assertEqual(sweeplogs['filenum'], 9111) def test_get_default_data_infos(self): self.test__set_default_data_descriptors() default_infos = self.E.get_default_data_infos() expected_info = DataInfo('i_sense') self.assertEqual(default_infos['cscurrent'], expected_info) def test_clear_caches(self): self.E.clear_caches() self.assertTrue(True)
dat_dir = os.path.abspath('fixtures/dats/2020Sep') """ Contents of dat_dir relevant in this file: Dat9111: Square entropy with dS ~Ln2 """ # Where to put outputs (i.e. DatHDFs) output_dir = os.path.abspath('Outputs/test_DatHDFBuilder') print(os.path.abspath('unit')) Testing_Exp2HDF = get_testing_Exp2HDF(dat_dir, output_dir) # SetUp before tests helpers.clear_outputs(output_dir) exp2hdf = Testing_Exp2HDF(9111, 'base') builder = DatHDFBuilder(exp2hdf, 'min') hdf_folder_path = os.path.join(output_dir, 'Dat_HDFs') dat_hdf_path = os.path.join( hdf_folder_path, 'dat9111.h5') # if datname=='base' it's not in filepath class TestDatHDFBuilder(TestCase): def _del_hdf_contents(self): if os.path.exists(hdf_folder_path): for root, dirs, files in os.walk(hdf_folder_path): for f in files: os.remove(os.path.join(hdf_folder_path, f)) for d in dirs: shutil.rmtree(os.path.join(hdf_folder_path, d))
class TestFittingAttribute(TestCase): helpers.clear_outputs(output_dir) dat = helpers.init_testing_dat(9111, output_dir) T: transition.Transition = Testing_Transition(dat) def tearDown(self): """Runs AFTER every test""" pass def test_get_default_params(self): default_pars = self.T.get_default_params() self.assertEqual(transition.default_transition_params(), default_pars) def test_get_default_func(self): func = self.T.get_default_func() self.assertEqual(transition.i_sense, func) def test_default_data_names(self): names = self.T.default_data_names() print(names) expected = ['x', 'i_sense'] self.assertEqual(expected, names) def test_clear_caches(self): self.T.clear_caches() self.assertTrue(True) def test_get_centers(self): centers = self.T.get_centers() expected = [ 28.945195081474278, 30.14704210128557, 18.172868224059584, 13.886815652413931, 15.613973966508519 ] close = [ np.isclose(e, r, atol=0.01, rtol=0.001) for e, r in zip(expected, centers[0:5]) ] print(close) self.assertTrue(all(close)) def test_avg_data(self): avg = self.T.avg_data self.assertEqual(70842, sum(~np.isnan(avg))) def test_avg_x(self): avg_x = self.T.avg_x print(avg_x) expected = [-296.65248355, -296.64424349, -296.63600343] self.assertTrue(np.allclose(expected, avg_x[:3], atol=0.00001)) def test_avg_data_std(self): avg_data_std = self.T.avg_data_std print(avg_data_std) expected = [0.02174817, 0.02046346, 0.01803641] self.assertTrue(np.allclose(expected, avg_data_std[0:3], atol=0.0001)) def test_avg_fit(self): avg_fit = self.T.avg_fit self.assertAlmostEqual(13.7, avg_fit.best_values.theta, delta=0.1) def test_row_fits(self): row_fits = self.T.row_fits for f in row_fits: self.assertIsInstance(f.best_values.mid, float) def test_get_avg_data(self): avg_data = self.T.get_avg_data(name='testavg') avd2, avg_std, avg_x = self.T.get_avg_data(return_std=True, return_x=True, name='testavg') self.assertTrue( np.allclose(avg_data, avd2, atol=0.0001, equal_nan=True)) self.assertIsInstance(avg_std, np.ndarray) def test__make_avg_data(self): self.test_get_avg_data() self.assertTrue(True) def test_get_fit_make(self): fit = self.T.get_fit(which='row', row=10, name='test_fit', check_exists=False) print(fit.best_values) expected = 19.57 self.assertTrue(np.isclose(expected, fit.best_values.mid, atol=0.01)) return fit def test_get_fit(self): ofit = self.test_get_fit_make() fit = self.T.get_fit(which='row', row=10, name='test_fit', check_exists=True) self.assertEqual(ofit, fit) with self.assertRaises(NotFoundInHdfError): self.T.get_fit(name='non_existing', check_exists=True) def test__get_fit_from_path(self): self.test_avg_fit() path = '/Transition/Avg Fits/default_avg' fit = self.T._get_fit_from_path(path) print(fit.best_values) self.assertAlmostEqual(13.7, fit.best_values.theta, delta=0.1) # Test on non existing path path = self.test__generate_fit_path() with self.assertRaises(NotFoundInHdfError): self.T._get_fit_from_path(path) def test_fit_paths(self): [ self.T.get_fit('row', i, 'few_test_fits', check_exists=False) for i in range(5) ] # Generate a few fits # rows = self.T.row_fits # To generate some fit paths if not already existing paths = self.T.fit_paths self.assertIsInstance(paths, FitPaths) rows = self.T.fit_paths.row_fits expected = '/Transition/Row Fits/0/few_test_fits_row[0]' self.assertEqual(expected, rows['few_test_fits_row[0]']) def test__get_fit_path_from_fit_id(self): params = transition.default_transition_params() params[ 'const'].value = 4.001 # So I know it doesn't match any other tests func = transition.i_sense [ self.T.get_fit('row', i, 'few_test_fits', initial_params=params, fit_func=func, check_exists=False, overwrite=True) for i in range(2) ] # Generate a few fits # fit_path: str = list(self.T.fit_paths.all_fits.values())[0] # print(fit_path) # fit: FitInfo = self.T._get_fit_from_path(fit_path) # print(params, fit.params) params = transition.default_transition_params( ) # In case they were modified during fitting params['const'].value = 4.001 # To match same as before fit_id = FitIdentifier(params, transition.i_sense, self.T.data[0]) path = self.T._get_fit_path_from_fit_id(fit_id) self.assertEqual('/Transition/Row Fits/0/few_test_fits_row[0]', path) def test__get_fit_path_from_name(self): self.test_get_fit_make() path = self.T._get_fit_path_from_name('test_fit', which='row', row=10) print(path) expected = '/Transition/Row Fits/10/test_fit_row[10]' self.assertEqual(expected, path) def test__generate_fit_path(self): path = self.T._generate_fit_path(which='avg', name='new_fit_path') print(path) expected = '/Transition/Avg Fits/new_fit_path_avg' self.assertEqual(expected, path) return path def test__save_fit(self): fit = FitInfo() self.T._save_fit(fit, which='avg', name='test_save_fit') with h5py.File(self.T.hdf.hdf_path, 'r') as f: print('debug here to find where the file is saved') group = f.get('/Transition/Avg Fits/test_save_fit_avg') self.assertIsNotNone(group) def test__get_fit_parent_group_name(self): name = self.T._get_fit_parent_group_name(which='row', row=1) print(name) expected = '/Transition/Row Fits/1' name2 = self.T._get_fit_parent_group_name(which='avg') print(name2) expected2 = '/Transition/Avg Fits' self.assertEqual(expected, name) self.assertEqual(expected2, name2) def test__calculate_fit(self): x = np.linspace(0, 10, 10000) np.random.seed(0) data = (np.random.random(10000) * 2 - 1) + 2 * x + 5 def line(x, a, c): return x * a + c params = lm.Parameters() params.add('a', 1) params.add('c', 0) fit = self.T._calculate_fit(x=x, data=data, params=params, func=line, auto_bin=True) print(fit.best_values) self.assertTrue( np.allclose((1.9993, 4.9964), (fit.best_values.a, fit.best_values.c), atol=0.001)) def test_initialize_minimum(self): self.T.initialize_minimum() self.assertTrue(True) def test_set_default_data_descriptors(self): self.T.set_default_data_descriptors() desc = self.T.specific_data_descriptors_keys['i_sense'] self.assertIsInstance(desc, DataDescriptor) def test__get_fit_saved_name(self): avg_name = self.T._generate_fit_saved_name('test', which='avg') self.assertEqual('test_avg', avg_name) row_name = self.T._generate_fit_saved_name('test', which='row', row=17) self.assertEqual('test_row[17]', row_name) with self.assertRaises(ValueError): a = self.T._generate_fit_saved_name('test', which='not_valid')
class TestAWG(TestCase): helpers.clear_outputs(output_dir) dat = helpers.init_testing_dat(9111, output_directory=output_dir) A = AWG(dat) def tearDown(self) -> None: """Runs AFTER every test """ pass def test_info(self): info = self.A.info print(info) expected = AWGtuple(awg_used=True, outputs={ 0: [0], 1: [1] }, wave_len=492, num_adcs=1, samplingFreq=6060.6, measureFreq=6060.6, num_cycles=1, num_steps=148) for k in expected._fields: self.assertEqual(getattr(expected, k), getattr(info, k)) def test_aws(self): aws = self.A.AWs print(aws) expected = (np.array([[ -416.66666, -333.33334, -250., -166.66667, -83.333336, 0., 83.333336, 166.66667, 250., 333.33334, 416.66666, 500., 416.66666, 333.33334, 250., 166.66667, 83.333336, 0., -83.333336, -166.66667, -250., -333.33334, -416.66666, -500. ], [ 4., 4., 4., 4., 4., 103., 4., 4., 4., 4., 4., 103., 4., 4., 4., 4., 4., 103., 4., 4., 4., 4., 4., 103. ]]), np.array([[ 65.375, 52.3, 39.225, 26.15, 13.075, 0., -13.075, -26.15, -39.225, -52.3, -65.375, -78.45, -65.375, -52.3, -39.225, -26.15, -13.075, 0., 13.075, 26.15, 39.225, 52.3, 65.375, 78.45 ], [ 4., 4., 4., 4., 4., 103., 4., 4., 4., 4., 4., 103., 4., 4., 4., 4., 4., 103., 4., 4., 4., 4., 4., 103. ]])) self.assertTrue( all([ np.allclose(exp, aw) for exp, aw in zip(expected, aws.values()) ])) def test_freq(self): print(self.A.freq) self.assertTrue(np.isclose(12.318, self.A.freq, atol=0.001)) def test_measure_freq(self): print(self.A.measure_freq) self.assertEqual(6060.6, self.A.measure_freq) def test_numpts(self): print(self.A.numpts) self.assertEqual(72816, self.A.numpts) def test_true_x_array(self): print(self.A.true_x_array) expected = np.linspace(-276.57000732, 323.42999268, 148) self.assertTrue(np.allclose(expected, self.A.true_x_array)) def test_get_single_wave(self): expected = [ -416.66665649, -416.66665649, -416.66665649, -416.66665649, -333.33334351, -333.33334351, -333.33334351, -333.33334351, -250., -250., -250., -250., -166.66667175, -166.66667175, -166.66667175, -166.66667175, -83.33333588, -83.33333588, -83.33333588, -83.33333588, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 0., 0, 0., 0., 0., 83.33333588, 83.33333588, 83.33333588, 83.33333588, 166.66667175, 166.66667175, 166.66667175, 166.66667175, 250., 250., 250., 250., 333.33334351, 333.33334351, 333.33334351, 333.33334351, 416.66665649, 416.66665649, 416.66665649, 416.66665649, 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 500., 416.66665649, 416.66665649, 416.66665649, 416.66665649, 333.33334351, 333.33334351, 333.33334351, 333.33334351, 250., 250., 250., 250., 166.66667175, 166.66667175, 166.66667175, 166.66667175, 83.33333588, 83.33333588, 83.33333588, 83.33333588, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., -83.33333588, -83.33333588, -83.33333588, -83.33333588, -166.66667175, -166.66667175, -166.66667175, -166.66667175, -250., -250., -250., -250., -333.33334351, -333.33334351, -333.33334351, -333.33334351, -416.66665649, -416.66665649, -416.66665649, -416.66665649, -500., -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500, -500., -500., -500., -500., -500., -500., -500., -500., -500., -500., -500., -500. ] self.assertTrue(np.allclose(expected, self.A.get_single_wave(0))) print(self.A.get_single_wave(1).shape) self.assertTrue(492, self.A.get_single_wave(1).shape) with self.assertRaises(NotFoundInHdfError): self.A.get_single_wave(3) def test_get_full_wave(self): print(self.A.get_full_wave(0).shape) self.assertEqual((72816, ), self.A.get_full_wave(0).shape) with self.assertRaises(NotFoundInHdfError): self.A.get_full_wave(3) def test_get_single_wave_masks(self): print(self.A.get_single_wave_masks(0).shape) self.assertEqual((24, 492), self.A.get_single_wave_masks(0).shape) with self.assertRaises(NotFoundInHdfError): self.A.get_single_wave_masks(3) def test_get_full_wave_masks(self): print(self.A.get_full_wave_masks(0).shape) self.assertTrue( np.allclose((24, 72816), self.A.get_full_wave_masks(0).shape)) with self.assertRaises(NotFoundInHdfError): self.A.get_full_wave_masks(3) def test_eval(self): for x, expected in zip([-276.57001, -275.33398, -274.41110, 323.42999], [-416.7, 500, 83.3, -500]): print(self.A.eval(x, wave_num=0)) self.assertTrue( np.isclose(expected, self.A.eval(x, wave_num=0), atol=0.1))
class TestData(TestCase): helpers.clear_outputs(output_dir) dat = helpers.init_testing_dat(9111, output_directory=output_dir) D: data.Data = Testing_Data(dat) def setUp(self) -> None: """Runs BEFORE every test""" pass def tearDown(self): """Runs AFTER every test""" pass def test__set_exp_config_data_descriptors(self): self.D._set_exp_config_DataDescriptors() with h5py.File(self.D.hdf.hdf_path, 'r') as f: g = f.get(self.D.group_name).get('Descriptors') expected_descriptor = DataDescriptor( data_path='/Experiment Copy/cscurrent_2d') descriptor = HDU.get_attr(g, 'i_sense', dataclass=DataDescriptor) self.assertEqual(descriptor, expected_descriptor) def test_keys(self): self.D.initialize_minimum() print(self.D.keys) self.assertEqual( set(), { 'y', 'Experiment Copy/x_array', 'i_sense', 'Experiment Copy/fdAW_1', 'x', 'Experiment Copy/fdAW_0', 'x_array', 'Experiment Copy/cscurrent_2d', 'Experiment Copy/y_array' } - set(self.D.keys)) def test_data_keys(self): self.D.initialize_minimum() keys = self.D.data_keys self.assertEqual( set(), { 'Experiment Copy/cscurrent_2d', 'Experiment Copy/fdAW_0', 'Experiment Copy/fdAW_1', 'Experiment Copy/x_array', 'Experiment Copy/y_array' } - set(keys)) def test__get_data_keys(self): keys = self.D._get_data_keys() expected = [ 'Experiment Copy/cscurrent_2d', 'Experiment Copy/fdAW_0', 'Experiment Copy/fdAW_1', 'Experiment Copy/x_array', 'Experiment Copy/y_array' ] self.assertEqual(expected, keys) def test_data_descriptors(self): self.D.initialize_minimum() descriptors = self.D.data_descriptors expected_descriptor = DataDescriptor('/Experiment Copy/cscurrent_2d') expected_descriptor_hash = hash(expected_descriptor) self.assertTrue(expected_descriptor_hash in [hash(d) for d in descriptors.values()]) def test__get_all_descriptors(self): self.D.initialize_minimum() descriptors = self.D._get_all_descriptors() expected_descriptor = DataDescriptor('/Experiment Copy/cscurrent_2d') # expected_descriptor_hash = hash(expected_descriptor) # print([expected_descriptor == d for d in descriptors.values()]) # print([expected_descriptor is d for d in descriptors.values()]) # print([hash(expected_descriptor) == hash(d) for d in descriptors.values()]) # print(f'{expected_descriptor}\n{list(descriptors.values())[0]}') # print(expected_descriptor.__eq__(list(descriptors.values())[0])) # print(hash(expected_descriptor), hash(list(descriptors.values())[0])) # print(expected_descriptor.__class__, list(descriptors.values())[0].__class__) self.assertTrue(expected_descriptor in descriptors.values()) def test_get_data_descriptor(self): self.D.initialize_minimum() d = self.D.get_data_descriptor('i_sense') expected = DataDescriptor('/Experiment Copy/cscurrent_2d') self.assertEqual(d, expected) def test__get_default_descriptor_for_data(self): # self.D.initialize_minimum() descriptors = [ self.D._get_default_descriptor_for_data(name) for name in self.D.data_keys ] expected_descriptor = DataDescriptor('/Experiment Copy/cscurrent_2d') expected_descriptor_hash = hash(expected_descriptor) self.assertTrue(expected_descriptor in descriptors) def test__get_data_path_from_hdf(self): path = self.D._get_data_path_from_hdf('cscurrent_2d') self.assertEqual(path, '/Experiment Copy/cscurrent_2d') def test_set_data_descriptor(self): self.D.initialize_minimum() descriptor = DataDescriptor('/Experiment Copy/cscurrent_2d', offset=10, multiply=20) self.D.set_data_descriptor(descriptor, name='test') d = self.D.get_data_descriptor('test', filled=False) self.assertEqual(descriptor, d) def test_DataDescriptor_multiply_offset(self): self.D.initialize_minimum() descriptor = DataDescriptor('/Experiment Copy/cscurrent_2d', offset=10, multiply=20) self.D.set_data_descriptor(descriptor, name='test') d = self.D.get_data_descriptor('test', filled=True) o_d = self.D.get_data_descriptor('i_sense', filled=True) self.assertTrue(np.allclose((o_d.data + 10) * 20, d.data, atol=1e-5)) def test_set_data_descriptor_raises(self): with self.assertRaises(FileNotFoundError): descriptor = DataDescriptor('notafile') self.D.set_data_descriptor(descriptor, name='test2') def test_get_data(self): self.D.initialize_minimum() isense = self.D.get_data('i_sense') orig_x = self.D.get_data('x_array') x = self.D.get_data('x') self.assertTrue(np.all(orig_x == x)) self.assertEqual(isense.shape, (50, 72816)) def test_get_orig_data(self): self.D.initialize_minimum() d = self.D.get_data_descriptor('i_sense') d.multiply = 2.0 self.D.set_data_descriptor(d, 'i_sense') mod_isense = self.D.get_data('i_sense') orig_isense = self.D.get_orig_data('i_sense') self.assertTrue(np.all(orig_isense == mod_isense / 2.0)) def test_modifiy_data(self): self.D.initialize_minimum() d = self.D.get_data_descriptor('x') odata = d.data[:] d.multiply = 2.0 d.offset = 10 self.D.set_data_descriptor(d) ndata = self.D.get_data('x') self.assertTrue(np.allclose(odata, (ndata / 2.0 - 10), atol=1e-5)) def test_set_data(self): self.D.initialize_minimum() data = np.ones((100, 1000, 10)) self.D.set_data(data, 'test_data') get_data = self.D.get_data('test_data') self.assertTrue(np.allclose(data, get_data)) def test_clear_caches(self): self.D.clear_caches() self.assertTrue(True) def test__initialize_minimum(self): self.D.initialize_minimum() self.assertTrue(self.D.initialized)
class TestLogs(TestCase): """Note: Many of these tests depend on dat.ExpConfig working well, so look there if these fail too.""" # Initial Setup helpers.clear_outputs(output_dir) dat = helpers.init_testing_dat(9111, output_dir) Logs = Testing_Logs( dat ) # This should make Logs without running init, and will not assign it to the dat yet def tearDown(self): """Runs AFTER every test""" pass def setUp(self): """Runs BEFORE every test""" self.Logs._init_sweeplogs() def test_0_init_sweeplogs(self): # This has to run before all the others # Note: I run this before ALL tests anyway self.Logs._init_sweeplogs() self.assertIsInstance(self.Logs.sweeplogs, dict) def test_1__get_sweeplogs_from_exp(self): sweeplogs = self.Logs._get_sweeplogs_from_exp() self.assertIsInstance(sweeplogs, dict) def test_2__init_srss(self): self.Logs._init_srss() srss = self.Logs.srss self.assertIsInstance(srss, logs.SRSs) def test_3__init_babydac(self): self.Logs._init_babydac() bds = self.Logs.bds self.assertEqual(bds['CA0 offset'], -100) def test_4__init_fastdac(self): self.Logs._init_fastdac() fds = self.Logs.fds self.assertEqual(fds['LP*2'], -490.11) fastdac = self.Logs.Fastdac self.assertEqual(fastdac.measure_freq, 6060.6) self.assertEqual(fastdac.dacs, fds) def test_5__init_awg(self): self.Logs._init_awg() awg: logs.AWGtuple = self.Logs.awg # expected = Logs.AWGtuple(outputs={0: [0], 1: [1]}, wave_len=492, num_adcs=1, samplingFreq=6060.6, # measureFreq=6060.6, num_cycles=1, num_steps=148) expected = [{0: [0], 1: [1]}, 492, 1, 6060.6, 6060.6, 1, 148] self.assertEqual(expected, [ awg.outputs, awg.wave_len, awg.num_adcs, awg.samplingFreq, awg.measureFreq, awg.num_cycles, awg.num_steps ]) def test_6__init_temps(self): self.Logs._init_temps() temps: logs.TEMPtuple = self.Logs.temps expected = [49.824, 3.8568, 4.671, 0.0499335, 0.66458] self.assertEqual( expected, [temps.fiftyk, temps.fourk, temps.mag, temps.mc, temps.still]) def test_7__init_mags(self): self.Logs._init_mags() mags = self.Logs.mags expected = [-49.98, 'magy', 54.33] self.assertEqual(expected, [mags.magy.field, mags.magy.name, mags.magy.rate]) def test_7a__init_other(self): self.Logs._init_other() key_expected = { 'comments': 'transition, square entropy, repeat, ', 'xlabel': 'LP*200 (mV)', 'ylabel': 'Repeats', 'measure_freq': 6060.6, 'sampling_freq': 6060.6, 'sweeprate': 49.939, } for k, v in key_expected.items(): val = getattr(self.Logs, k) if isinstance(val, float): self.assertTrue(np.isclose(val, v, atol=0.001)) else: self.assertEqual(v, val) def test_8__initialize_minimum(self): self.Logs.initialize_minimum() self.assertTrue(self.Logs.initialized) def test_9_assign_to_dat(self): self.dat.Logs = self.Logs self.assertEqual(self.dat.Logs, self.Logs)