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_solvent_unset(): rxn = Reaction() rxn.solvent = 'w' assert len(rxn) == 1 rxn.solvent = None assert len(rxn) == 0
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_iter_sorting_solvent(): as_list = lambda rxn: [x.name for x in rxn] rxn = Reaction() rxn.solvent = 'w' rxn['x'] assert as_list(rxn) == ['w', 'x'] rxn = Reaction() rxn.solvent = 'w' rxn['w'] rxn['x'] assert as_list(rxn) == ['w', 'x'] rxn = Reaction() rxn.solvent = 'w' rxn['x'] rxn['w'] assert as_list(rxn) == ['x', 'w'] rxn = Reaction() rxn.solvent = 'w' rxn['x'].order = 2 rxn['w'].order = 1 assert as_list(rxn) == ['w', 'x'] rxn = Reaction() rxn.solvent = 'w' rxn['w'].order = 2 rxn['x'].order = 1 assert as_list(rxn) == ['x', 'w']
def test_reaction_iter_non_solvent(): as_list = lambda rxn: [x.name for x in rxn] rxn = Reaction() rxn.solvent = None assert as_list(rxn.iter_non_solvent_reagents()) == [] rxn.solvent = 'w' assert as_list(rxn.iter_non_solvent_reagents()) == [] rxn['x'] assert as_list(rxn.iter_non_solvent_reagents()) == ['x']
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_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_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_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_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_iter_by_flag(): as_list = lambda rxn: [x.name for x in rxn] rxn = Reaction() rxn.solvent = None assert as_list(rxn.iter_reagents_by_flag('a')) == [] rxn.solvent = 'w' assert as_list(rxn.iter_reagents_by_flag('a')) == [] rxn['w'].flags.add('a') assert as_list(rxn.iter_reagents_by_flag('a')) == ['w'] rxn['w'].flags.remove('a') assert as_list(rxn.iter_reagents_by_flag('a')) == [] rxn['x'] assert as_list(rxn.iter_reagents_by_flag('a')) == [] rxn['x'].flags.add('a') assert as_list(rxn.iter_reagents_by_flag('a')) == ['x'] rxn['x'].flags.remove('a') assert as_list(rxn.iter_reagents_by_flag('a')) == []
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_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_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_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_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_solvent_repr(): rxn = Reaction() rxn.solvent = 'w' assert re.match(r"Solvent\(reaction=\d{4}, name='w'\)", repr(rxn['w']))