def test_ngram_3(data): ngram = NGram(sample_order=5) ngram.fit(data['pg'][0][:20], train_order=5) def on_errors(self, error): if isinstance(error, MolConvertError): raise error else: return error.old_smi np.random.seed(123456) ngram.on_errors = types.MethodType(on_errors, ngram) with pytest.raises(MolConvertError): old_smis = ['CC(=S)C([*])(C)=CCC([*])'] ngram.proposal(old_smis) def on_errors(self, error): if isinstance(error, GetProbError): raise error else: return error.old_smi np.random.seed(654321) ngram.on_errors = types.MethodType(on_errors, ngram) with pytest.raises(GetProbError): old_smis = ['C([*])C([*])(C1=C(OCCC)C=CC(Br)C1)'] ngram.proposal(old_smis)
def test_ngram_2(data): ngram = NGram() with pytest.warns(RuntimeWarning, match='<sample_order>'): ngram.fit(data['pg'][0][:20], train_order=5) assert ngram._train_order == (1, 5) assert ngram.sample_order == (1, 5) assert ngram.ngram_table is not None np.random.seed(123456) with pytest.warns(RuntimeWarning, match='can not convert'): old_smis = ['CC(=S)C([*])(C)=CCC([*])'] tmp = ngram.proposal(old_smis) assert tmp == old_smis np.random.seed(654321) with pytest.warns(RuntimeWarning, match='get_prob: '): old_smis = ['C([*])C([*])(C1=C(OCCC)C=CC(Br)C1)'] tmp = ngram.proposal(old_smis) assert tmp == old_smis