def test_solvent_key(): rxn = Reaction() rxn.solvent = 'w' rxn['x'] w = rxn['w'] rxn['y'] assert w.key == 'w' # Set the key without changing it. This shouldn't cause problems: rxn.solvent = 'w' # Re-key the solvent via the reaction: rxn.solvent = 'w2' assert 'w' not in rxn assert 'w2' in rxn assert rxn['w2'] is w assert rxn['w2'].key == 'w2' # Re-key the solvent via itself: w.key = 'w3' assert 'w' not in rxn assert 'w2' not in rxn assert 'w3' in rxn assert rxn['w3'] is w assert rxn['w3'].key == 'w3'
def test_reaction_len_contains(): rxn = Reaction() rxn.solvent = None assert len(rxn) == 0 assert 'x' not in rxn assert 'y' not in rxn assert 'w' not in rxn rxn['x'] assert len(rxn) == 1 assert 'x' in rxn assert 'y' not in rxn assert 'w' not in rxn rxn['y'] assert len(rxn) == 2 assert 'x' in rxn assert 'y' in rxn assert 'w' not in rxn rxn.solvent = 'w' assert len(rxn) == 3 assert 'x' in rxn assert 'y' in rxn assert 'w' in rxn rxn['w'] assert len(rxn) == 3 assert 'x' in rxn assert 'y' in rxn assert 'w' in rxn
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_solvent_unset(): rxn = Reaction() rxn.solvent = 'w' assert len(rxn) == 1 rxn.solvent = None assert len(rxn) == 0
def test_reaction_iter_sorting(x, y, solvent, expected): as_list = lambda rxn: [x.name for x in rxn] rxn = Reaction() rxn.solvent = solvent rxn['x'].order = x rxn['y'].order = y assert as_list(rxn) == 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(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_reaction_getitem(): rxn = Reaction() assert isinstance(rxn['x'], Reagent) assert rxn['x'] is rxn['x'] assert rxn['x'].name == 'x' rxn.solvent = 'w' assert isinstance(rxn['w'], Solvent) assert rxn['w'] is rxn['w'] assert rxn['w'].name == rxn.solvent == 'w'
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_solvent(): rxn = Reaction() rxn.solvent = 'w' assert rxn['w'].master_mix == True assert rxn['w'].order == None rxn['w'].master_mix = False rxn['w'].order = 1 assert rxn['w'].master_mix == False assert rxn['w'].order == 1
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_delitem(): rxn = Reaction() rxn.solvent = 'w' rxn['x'] assert 'x' in rxn assert 'w' in rxn del rxn['x'] assert 'x' not in rxn del rxn['w'] assert 'w' not in rxn assert rxn.solvent == None
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_volume(given, expected): rxn = Reaction() x = Reagent(rxn, 'x') assert x.volume == None x.volume = given assert x.volume == expected
def test_reagent_order(): rxn = Reaction() x = Reagent(rxn, 'x') assert x.order == None x.order = 1 assert x.order == 1
def test_reagent_stock_conc(given, expected): rxn = Reaction() x = Reagent(rxn, 'x') assert x.stock_conc == None x.stock_conc = given assert x.stock_conc == expected
def test_reaction_repr(): rxn = Reaction() rxn.solvent = None assert repr(rxn) == "Reaction()" rxn.solvent = 'w' assert repr(rxn) == "Reaction('w')" rxn['x'] assert repr(rxn) == "Reaction('w', 'x')" rxn['y'] assert repr(rxn) == "Reaction('w', 'x', 'y')" rxn['w'] assert repr(rxn) == "Reaction('x', 'y', 'w')"
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_solvent_name(): rxn = Reaction() rxn.solvent = 'w' w = rxn['w'] assert w.key == 'w' assert w.name == 'w' assert 'w' in rxn assert 'w2' not in rxn w.name = 'w2' assert w.key == 'w' assert w.name == 'w2' assert 'w' in rxn assert 'w2' not in rxn
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_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_reaction_iter(): as_list = lambda rxn: [x.name for x in rxn] rxn = Reaction() rxn.solvent = None assert as_list(rxn) == [] rxn.solvent = 'w' assert as_list(rxn) == ['w'] rxn['x'] assert as_list(rxn) == ['w', 'x'] rxn['y'] assert as_list(rxn) == ['w', 'x', 'y'] rxn['w'] assert as_list(rxn) == ['x', 'y', 'w']
def test_reaction_from_text_catalog_num(): rxn = Reaction.from_text("""\ Reagent Stock Volume MM? Cat ======= ===== ======= === === w to 8 µL yes x 2x 3 µL no 101 """) assert rxn['w'].catalog_num == '' assert rxn['x'].catalog_num == '101'
def test_reaction_from_text_flags(): rxn = Reaction.from_text("""\ Reagent Stock Volume MM? Flags ======= ===== ======= === ===== w to 8 µL yes a x 2x 3 µL no a,b """) assert rxn['w'].flags == {'a'} assert rxn['x'].flags == {'a', 'b'}
def test_reagent_master_mix(): rxn = Reaction() x = Reagent(rxn, 'x') assert not x.master_mix x.master_mix = True assert x.master_mix x.master_mix = False assert not x.master_mix
def test_reaction_from_text(text, volume, reagents): rxn = Reaction.from_text(text) assert len(rxn) == len(reagents) assert rxn.volume == volume for name, expected in reagents.items(): volume, stock_conc, master_mix = expected if volume != ...: assert rxn[name].volume == volume if stock_conc != ...: assert rxn[name].stock_conc == stock_conc if master_mix != ...: assert rxn[name].master_mix == master_mix
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_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_reagent_key(): rxn = Reaction() x = Reagent(rxn, 'x') assert x.key == 'x' assert 'x' in rxn assert 'y' not in rxn x.key = 'y' assert x.key == 'y' assert 'x' not in rxn assert 'y' in rxn