def test_reagent_hold_stock_conc_in_place(): rxn = Reaction() rxn.volume = '10 µL' x = Reagent(rxn, 'x') x.volume = '1 µL' x.stock_conc = '10 ng/µL' assert x.conc == '1 ng/µL' x.hold_stock_conc.volume += '1 µL' assert x.conc == '2 ng/µL' x.hold_stock_conc.volume -= '1 µL' assert x.conc == '1 ng/µL' x.hold_stock_conc.volume *= 2 assert x.conc == '2 ng/µL' x.hold_stock_conc.volume /= 2 assert x.conc == '1 ng/µL' x.hold_stock_conc.conc += '1 ng/µL' assert x.volume == '2 µL' x.hold_stock_conc.conc -= '1 ng/µL' assert x.volume == '1 µL' x.hold_stock_conc.conc *= 2 assert x.volume == '2 µL' x.hold_stock_conc.conc /= 2 assert x.volume == '1 µL'
def test_reagent_conc(volume, stock_conc, rxn_volume, expected): rxn = Reaction() rxn.volume = rxn_volume x = Reagent(rxn, 'x') x.volume = volume x.stock_conc = stock_conc assert x.conc == expected
def test_reagent_volume_implicit_solvent(): # When iterating through the reagents of a reaction, new solvent objects # can get created on the fly. This can break code that assumes the # reaction will always return the exact same solvent instance. rxn = Reaction() rxn.volume = '10 µL' for reagent in rxn: assert reagent.volume == '10 µL'
def test_reagent_conc_raises(volume, stock_conc, rxn_volume, err): rxn = Reaction() x = Reagent(rxn, 'Reagent Name') if rxn_volume: rxn.volume = rxn_volume if volume: x.volume = volume if stock_conc: x.stock_conc = stock_conc with pytest.raises(ValueError, match=err): x.conc
def test_reaction_hold_ratios(v1, r1, v2, r2): rxn = Reaction() rxn.volume = v1 for k, v in r1.items(): rxn[k].volume = v # Set the volume without scaling the reagents: rxn.volume = v2 assert rxn.volume == v2 assert rxn.hold_ratios.volume == v2 for k, v in r1.items(): assert rxn[k].volume == v # Set the volume and scale the reagents: rxn.volume = v1 rxn.hold_ratios.volume = v2 assert rxn.volume == v2 assert rxn.hold_ratios.volume == v2 for k, v in r2.items(): assert rxn[k].volume == v
def test_reaction_volume_no_solvent(): rxn = Reaction() del rxn.solvent assert rxn.volume == 0 rxn['x'].volume = '2 µL' assert rxn.volume == '2 µL' rxn['y'].volume = '1 µL' assert rxn.volume == '3 µL' with pytest.raises(ValueError, match="no solvent specified"): rxn.volume = '4 µL'
def test_reaction_hold_ratios_no_solvent(): rxn = Reaction() del rxn.solvent rxn['x'].volume = '1 µL' rxn['y'].volume = '2 µL' assert rxn.volume == '3 µL' with pytest.raises(ValueError, match="no solvent"): rxn.volume = '6 µL' rxn.hold_ratios.volume = '6 µL' assert rxn.volume == '6 µL' assert rxn['x'].volume == '2 µL' assert rxn['y'].volume == '4 µL'
def test_reagent_hold_stock_conc(rxn_volume, s1, v1, c1, v2, c2): rxn = Reaction() x = Reagent(rxn, 'x') y = Reagent(rxn, 'y') # Set volume: x.hold_stock_conc.volume = v2 assert x.volume == v2 # Set concentration: rxn.volume = rxn_volume y.stock_conc = s1 y.hold_stock_conc.conc = c2 assert y.volume == v2 assert y.stock_conc == s1 assert y.conc == c2
def test_fix_volumes(solvent, donor_before, acceptor_before, donor_after, acceptor_after): rxn = Reaction() rxn.solvent = solvent rxn.add_reagent('donor') rxn.add_reagent('acceptor') if solvent != 'donor': rxn['donor'].volume = donor_before, 'µL' if solvent != 'acceptor': rxn['acceptor'].volume = acceptor_before, 'µL' if solvent != 'water': rxn.volume = donor_before + acceptor_before, 'µL' rxn.fix_volumes('donor', 'acceptor') assert rxn['donor'].volume == (donor_after, 'µL') assert rxn['acceptor'].volume == (acceptor_after, 'µL')
def test_solvent_volume(): rxn = Reaction() rxn.solvent = 'w' rxn.volume = '10 µL' rxn['x'].volume = '1 µL' assert rxn['w'].volume == '9 µL' rxn['x'].volume = '2 µL' assert rxn['w'].volume == '8 µL' rxn['y'].volume = '1 µL' assert rxn['w'].volume == '7 µL' rxn['x'].volume = None with pytest.raises(ValueError): rxn['w'].volume
def test_reagent_hold_volume(rxn_volume, v1, s1, c1, s2, c2): rxn = Reaction() x = Reagent(rxn, 'x') y = Reagent(rxn, 'y') # Set stock concentration: x.hold_volume.stock_conc = s2 assert x.stock_conc == s2 # Set concentration: rxn.volume = rxn_volume y.volume = v1 y.hold_volume.conc = c2 assert y.volume == v1 assert y.stock_conc == s2 assert y.conc == c2
def test_reaction_free_volume(): rxn = Reaction() rxn.solvent = 'w' rxn.volume = '4 µL' assert rxn.free_volume == '4 µL' rxn['x'].volume = '1 µL' assert rxn.free_volume == '3 µL' assert rxn.get_free_volume_excluding('x') == '4 µL' rxn['y'].volume = '2 µL' assert rxn.free_volume == '1 µL' assert rxn.get_free_volume_excluding('x') == '2 µL' assert rxn.get_free_volume_excluding('y') == '3 µL' assert rxn.get_free_volume_excluding('x', 'y') == '4 µL' rxn['z'].volume = '1 µL' assert rxn.free_volume == '0 µL'
def test_reaction_hold_ratios_in_place(): rxn = Reaction() rxn.volume = '10 µL' rxn['x'].volume = '2 µL' rxn.hold_ratios.volume += '5 µL' assert rxn.volume == '15 µL' assert rxn['x'].volume == '3 µL' rxn.hold_ratios.volume -= '5 µL' assert rxn.volume == '10 µL' assert rxn['x'].volume == '2 µL' rxn.hold_ratios.volume *= 2 assert rxn.volume == '20 µL' assert rxn['x'].volume == '4 µL' rxn.hold_ratios.volume /= 2 assert rxn.volume == '10 µL' assert rxn['x'].volume == '2 µL'
def test_reaction_volume(given, expected): rxn = Reaction() assert rxn.volume == None rxn.volume = given assert rxn.volume == expected