def test_merge_uvvis_3(self): """Checks check_prev works in this context""" uvvis_prev_1 = UvvisSpectrum(peaks=[UvvisPeak(value='123')]) uvvis_prev_2 = UvvisSpectrum(peaks=[UvvisPeak(value='456')]) uvvis_current_1 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis_current_2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) comp_prev = Compound(uvvis_spectra=[uvvis_prev_1, uvvis_prev_2]) comp_current = Compound( uvvis_spectra=[uvvis_current_1, uvvis_current_2]) table_records = [comp_prev] comp_current = indep.merge_uvvis(comp_current, table_records) gold_prev = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }] }, { 'peaks': [{ 'value': '456', 'extinction': '40000' }] }] } gold_current = {} self.assertEqual(gold_prev, comp_prev.serialize()) self.assertEqual(gold_current, comp_current.serialize())
def test_is_contextual(self): """Test is_contextual method returns expected result.""" self.assertEqual(Compound(names=['Coumarin 343']).is_contextual, False) self.assertEqual( Compound(melting_points=[MeltingPoint(value='240')]).is_contextual, False) self.assertEqual( Compound(melting_points=[MeltingPoint(units='K')]).is_contextual, True) self.assertEqual( Compound(melting_points=[MeltingPoint( apparatus='Some apparatus')]).is_contextual, True) self.assertEqual( Compound(labels=['3a'], melting_points=[MeltingPoint(apparatus='Some apparatus') ]).is_contextual, False) self.assertEqual( Compound(uvvis_spectra=[UvvisSpectrum( apparatus='Some apparatus')]).is_contextual, True) self.assertEqual( Compound( uvvis_spectra=[UvvisSpectrum(peaks=[UvvisPeak( value='378')])]).is_contextual, False) self.assertEqual( Compound( uvvis_spectra=[UvvisSpectrum(peaks=[UvvisPeak( units='nm')])]).is_contextual, True)
def test_just_value_one_extinction(self): '''Tests just value for failure case with one extinction''' u = UvvisSpectrum() peak = UvvisPeak() peak.extinction = 12345 u.peaks.append(peak) self.assertEqual(u.just_value(), False)
def test_check_prev(self): uvvis_prev_1 = UvvisSpectrum(peaks=[UvvisPeak(value='123')]) uvvis_prev_2 = UvvisSpectrum(peaks=[UvvisPeak(value='456')]) uvvis_current_1 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis_current_2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) comp_prev = Compound(uvvis_spectra=[uvvis_prev_1, uvvis_prev_2]) comp_current = Compound( uvvis_spectra=[uvvis_current_1, uvvis_current_2]) table_records = [comp_prev] comp_current = indep.check_prev(comp_current, [], [0, 1], table_records) gold_prev = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }] }, { 'peaks': [{ 'value': '456', 'extinction': '40000' }] }] } gold_current = {} self.assertEqual(gold_prev, comp_prev.serialize()) self.assertEqual(gold_current, comp_current.serialize())
def test_just_value_multiple_values(self): u = UvvisSpectrum() peaks = [UvvisPeak(), UvvisPeak(), UvvisPeak()] values = [467, 234, 123] for i, peak in enumerate(peaks): peak.value = values[i] u.peaks.append(peak) self.assertEqual(u.just_value(), True)
def test_just_value_one_value(self): '''Tests just value for a spectrum with one value''' u = UvvisSpectrum() peak = UvvisPeak() peak.value = 467 u.peaks.append(peak) self.assertEqual(u.just_value(), True)
def test_get_indices(self): uvvis1 = UvvisSpectrum( peaks=[UvvisPeak( value='123'), UvvisPeak(value='456')]) uvvis2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis3 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) comp = Compound(uvvis_spectra=[uvvis1, uvvis2, uvvis3]) val, ext = indep.get_indices(comp) self.assertEqual(val, [0]) self.assertEqual(ext, [1, 2])
def test_merge_all_uvvis_2(self): uvvis1 = UvvisSpectrum(peaks=[UvvisPeak(value='345')]) uvvis2 = UvvisSpectrum(peaks=[UvvisPeak(value='123')]) comp = Compound(uvvis_spectra=[uvvis1, uvvis2]) gold = Compound(uvvis_spectra=[ UvvisSpectrum( peaks=[UvvisPeak(value='345'), UvvisPeak(value='123')]) ]) self.assertEqual(indep.merge_all_uvvis(comp), gold)
def test_merge_peaks(self): uvvis = UvvisSpectrum( peaks=[UvvisPeak(value='123'), UvvisPeak(extinction='35000')]) uvvis.merge_peaks(0, 1) gold = { 'peaks': [{ 'extinction': '35000', 'value': '123' }, { 'extinction': '35000' }] } self.assertEqual(gold, uvvis.serialize())
def test_merge_uvvis_1(self): """Checks merge_peak_obj works in this context""" uvvis = UvvisSpectrum(peaks=[ UvvisPeak(value='123'), UvvisPeak(value='456'), UvvisPeak(extinction='35000'), UvvisPeak(extinction='40000') ]) comp = Compound(uvvis_spectra=[uvvis]) table_records = [] resolved_comp = indep.merge_uvvis(comp, table_records) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] }] } print(resolved_comp.serialize()) self.assertEqual(gold, resolved_comp.serialize())
def test_get_peak_indices(self): peak1 = UvvisPeak(value='123') peak2 = UvvisPeak(extinction='35000') uvvis = UvvisSpectrum(peaks=[peak1, peak2]) val, ext = indep.get_peak_indices(uvvis) self.assertEqual(val, [0]) self.assertEqual(ext, [1])
def test_just_value(self): """Test just_value returns true appropriately""" self.assertEqual( UvvisSpectrum(peaks=[UvvisPeak(value='467')]).just_value(), True) self.assertEqual( UvvisSpectrum(peaks=[ UvvisPeak(value='467'), UvvisPeak(value='234'), UvvisPeak(value='123') ]).just_value(), True) self.assertEqual( UvvisSpectrum(peaks=[UvvisPeak(value=None)]).just_value(), False) self.assertEqual( UvvisSpectrum(peaks=[ UvvisPeak(value='467'), UvvisPeak(value='234'), UvvisPeak(extinction='12000') ]).just_value(), False)
def test_merge_peak_and_uvvis_obj(self): uvvis_value = UvvisSpectrum( peaks=[UvvisPeak( value='123'), UvvisPeak(value='456')]) uvvis2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis3 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) comp = Compound(uvvis_spectra=[uvvis_value, uvvis2, uvvis3]) resolved_comp = indep.merge_peak_and_uvvis_obj(comp, [0], [1, 2]) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'extinction': '35000', 'value': '123' }, { 'extinction': '40000', 'value': '456' }] }] } self.assertEqual(gold, resolved_comp.serialize())
def test_merge_all_uvvis_1(self): peak1 = UvvisPeak(value='123', extinction='35000') peak2 = UvvisPeak(value='456', extinction='40000') comp = Compound(uvvis_spectra=[ UvvisSpectrum(peaks=[peak1]), UvvisSpectrum(peaks=[peak2]) ]) comp = indep.merge_all_uvvis(comp) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] }] } self.assertEqual(gold, comp.serialize())
def test_merge_uvvis_4(self): """Checks merge_all_uvvis works in this context""" peak1 = UvvisPeak(value='123', extinction='35000') peak2 = UvvisPeak(value='456', extinction='40000') comp = Compound(uvvis_spectra=[ UvvisSpectrum(peaks=[peak1]), UvvisSpectrum(peaks=[peak2]) ]) row_compound = [] comp = indep.merge_uvvis(comp, row_compound) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] }] } self.assertEqual(gold, comp.serialize())
def test_merge_peaks_and_uvvis(self): """ Tests merge_peaks_and_uvvis correctly merges values from 1 uvvis object containing multiple peaks to a list of extinctions containing one peak each""" uvvis_value = UvvisSpectrum( peaks=[UvvisPeak( value='123'), UvvisPeak(value='456')]) uvvis_ext = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis_ext_2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) uvvis_value.merge_peaks_and_uvvis([uvvis_ext, uvvis_ext_2], [0, 1]) gold = { 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] } self.assertEqual(gold, uvvis_value.serialize())
def test_merge_peak_obj(self): uvvis = UvvisSpectrum(peaks=[ UvvisPeak(value='123'), UvvisPeak(value='456'), UvvisPeak(extinction='35000'), UvvisPeak(extinction='40000') ]) comp = Compound(uvvis_spectra=[uvvis]) resolved_comp = indep.merge_peak_obj(comp) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] }] } self.assertEqual(gold, resolved_comp.serialize())
def test_merge_uvvis(self): # Case 1 : one value per extinction uvvis1 = UvvisSpectrum(peaks=[UvvisPeak(value='345')]) uvvis2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis1.merge_uvvis(uvvis2) gold = {'peaks': [{'value': '345', 'extinction': '35000'}]} self.assertEqual(gold, uvvis1.serialize()) # Case 2 : One extinction, multiple values uvvis1 = UvvisSpectrum( peaks=[UvvisPeak( value='123'), UvvisPeak(value='456')]) uvvis2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis1.merge_uvvis(uvvis2) gold = { 'peaks': [{ 'extinction': '35000', 'value': '123' }, { 'extinction': '35000', 'value': '456' }] } self.assertEqual(gold, uvvis1.serialize())