def test_validate(self): with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=['validate', 'dna', 'ACGT']) as app: # run app app.run() # test that the CLI produced the correct output self.assertEqual(captured.stdout.get_text(), 'Form is valid') self.assertEqual(captured.stderr.get_text(), '') with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'validate', 'dna', 'ACG[id: "ala" | structure: {}]T'.format(ala_inchi) ]) as app: # run app app.run() # test that the CLI produced the correct output self.assertEqual(captured.stdout.get_text(), 'Form is valid') self.assertEqual(captured.stderr.get_text(), '') with self.assertRaisesRegex(SystemExit, '^Form is invalid'): with __main__.App(argv=['validate', 'dna', 'ACGT[']) as app: # run app app.run()
def test_help(self): with self.assertRaises(SystemExit): with __main__.App(argv=[]) as app: app.run() with self.assertRaises(SystemExit): with __main__.App(argv=['--help']) as app: app.run()
def test_version(self): with __main__.App(argv=['-v']) as app: with capturer.CaptureOutput(merged=False, relay=False) as captured: with self.assertRaises(SystemExit): app.run() self.assertEqual(captured.stdout.get_text(), bpforms.__version__) self.assertEqual(captured.stderr.get_text(), '') with __main__.App(argv=['--version']) as app: with capturer.CaptureOutput(merged=False, relay=False) as captured: with self.assertRaises(SystemExit): app.run() self.assertEqual(captured.stdout.get_text(), bpforms.__version__) self.assertEqual(captured.stderr.get_text(), '')
def verify_large_polymers(self, form_type, alphabet): # test Python API form = form_type() for i_trial in range(6): self.verify_large_polymer(form, alphabet, i_trial) # test CLI with __main__.App(argv=['get-properties', form.alphabet.id, alphabet * pow(2, 5)]) as app: app.run() with __main__.App(argv=['get-properties', form.alphabet.id, alphabet * pow(2, 5), '--ph', '7.4']) as app: app.run() # test REST API client = rest.app.test_client() rv = client.post('/api/bpform/', json=dict(alphabet=form.alphabet.id, seq=alphabet * pow(2, 5), ph=7.4, major_tautomer=True)) self.assertEqual(rv.status_code, 200)
def test_validate(self): with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App( argv=['validate', 'canonical_dna', 'ACGT']) as app: # run app app.run() # test that the CLI produced the correct output self.assertEqual(captured.stdout.get_text(), 'Form is valid') self.assertEqual(captured.stderr.get_text(), '') with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'validate', 'canonical_dna', ('ACG' '[id: "dI" | structure: "{}"' ' | l-bond-atom: P30' ' | l-displaced-atom: O33-1' ' | r-bond-atom: O34' ' | r-displaced-atom: H34' ' ]' 'T').format(dIMP_smiles) ]) as app: # run app app.run() # test that the CLI produced the correct output self.assertEqual(captured.stdout.get_text(), 'Form is valid') self.assertEqual(captured.stderr.get_text(), '') with self.assertRaisesRegex(SystemExit, '^Form is invalid'): with __main__.App( argv=['validate', 'canonical_dna', 'ACGT[']) as app: # run app app.run() with self.assertRaisesRegex(SystemExit, '^Form is invalid'): with __main__.App(argv=[ 'validate', 'canonical_dna', ('ACGT' '[id: "dI" | structure: "{}" | l-displaced-atom: O33-1 ]' ).format(dIMP_smiles) ]) as app: # run app app.run()
def test_get_major_micro_species(self): with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'get-major-micro-species', 'canonical_dna', ('[id: "dI" | structure: "{0}"' ' | l-bond-atom: P30' ' | l-displaced-atom: O33-1' ' | r-bond-atom: O34' ' | r-displaced-atom: H34' ' ]' '[id: "dI" | structure: "{0}"' ' | l-bond-atom: P30' ' | l-displaced-atom: O33-1' ' | r-bond-atom: O34' ' | r-displaced-atom: H34' ' ]').format(dIMP_smiles), '14.' ]) as app: # run app app.run() # test that the CLI produced the correct output smiles = captured.stdout.get_text() self.assertEqual( captured.stdout.get_text(), ('OC[C@H]1O[C@H](C[C@@H]1O)[N+]1(C=Nc2c1nc[n-]' 'c2=O)C1CC([O-])C(COP(=O)([O-])OC2CC(OC2COP(=O)' '([O-])[O-])[N+]2(C=Nc3c2nc[n-]c3=O)[C@H]2C[C@H]' '(O)[C@@H](CO)O2)O1')) with self.assertRaises(SystemExit): with __main__.App(argv=[ 'get-major-micro-species', 'canonical_dna', 'ACGT[', '7.' ]) as app: # run app app.run() with self.assertRaisesRegex(SystemExit, '^Form is invalid'): with __main__.App(argv=[ 'get-major-micro-species', 'canonical_dna', ('ACGT' '[id: "dI" | structure: "{}" | l-displaced-atom: O33-1 ]' ).format(dI_smiles), '7.' ]) as app: # run app app.run()
def test_get_properties(self): with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=['get-properties', 'dna', 'ACGT']) as app: # run app app.run() # test that the CLI produced the correct output text = captured.stdout.get_text() self.assertIn('Length: 4', text) self.assertIn('Formula: C39H46N15O28P4', text) self.assertIn('Molecular weight: 1296.769047992', text) self.assertIn('Charge: -5', text) self.assertEqual(captured.stderr.get_text(), '') with capturer.CaptureOutput(merged=False, relay=False) as captured: base_seq = ''.join([ '[structure: {}]'.format( bpforms.dna.dna_alphabet.A.get_inchi()), '[structure: {}]'.format( bpforms.dna.dna_alphabet.C.get_inchi()), '[structure: {}]'.format( bpforms.dna.dna_alphabet.G.get_inchi()), '[structure: {}]'.format( bpforms.dna.dna_alphabet.T.get_inchi()), ]) with __main__.App( argv=['get-properties', 'dna', base_seq, '--ph', '7.0' ]) as app: # run app app.run() # test that the CLI produced the correct output text = captured.stdout.get_text() self.assertIn('Length: 4', text) self.assertIn('Formula: C39H43N15O28P4', text) self.assertIn('Molecular weight: 1293.745047992', text) self.assertIn('Charge: -8', text) self.assertEqual(captured.stderr.get_text(), '') with self.assertRaises(SystemExit): with __main__.App(argv=['get-properties', 'dna', 'ACGT[']) as app: # run app app.run()
def test_protonate(self): with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'protonate', 'dna', '[id: "ala" | structure: {0}][id: "ala" | structure: {0}]'. format(ala_inchi), '14.' ]) as app: # run app app.run() # test that the CLI produced the correct output self.assertEqual( captured.stdout.get_text(), '[id: "ala" | structure: {0}][id: "ala" | structure: {0}]'. format(ala_inchi_ph_14)) self.assertEqual(captured.stderr.get_text(), '') with self.assertRaises(SystemExit): with __main__.App(argv=['protonate', 'dna', 'ACGT[', '7.']) as app: # run app app.run()
def test_viz_alphabet(self): path = os.path.join(self.tempdir, 'alphabet.html') with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App( argv=['viz-alphabet', 'canonical_dna', path]) as app: # run app app.run() # test that the CLI produced the correct output self.assertEqual(captured.stdout.get_text(), 'Visualization saved to {}'.format(path)) self.assertTrue(os.path.isfile(path))
def test_export_ontos(self): path = os.path.join(self.tempdir, 'onto.obo') with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'export-ontos', path, '--alphabet', 'protein', '--max-monomers', '10', '--max-xlinks', '10' ]) as app: # run app app.run() # test that the CLI produced the correct output self.assertEqual(captured.stdout.get_text(), 'Ontology saved to {}'.format(path)) self.assertTrue(os.path.isfile(path))
def test_build_alphabets(self): self.assertFalse(os.path.isfile(bpforms.alphabet.dna.filename)) with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'build-alphabets', '--alphabet', 'dna', '--max-monomers', '3' ]) as app: # run app app.run() # test that the CLI produced the correct output self.assertIn('Alphabets successfully built', captured.stdout.get_text()) self.assertTrue(os.path.isfile(bpforms.alphabet.dna.filename))
def test_get_properties(self): with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App( argv=['get-properties', 'canonical_dna', 'ACGT']) as app: # run app app.run() # test that the CLI produced the correct output text = captured.stdout.get_text() self.assertIn('Length: 4', text) self.assertNotIn('Structure: None', text) self.assertIn('Formula: C39', text) self.assertIn('Molecular weight: ', text) self.assertIn('Charge: -', text) self.assertEqual(captured.stderr.get_text(), '') with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'get-properties', 'canonical_dna', 'ACGT', '--ph', '7.0' ]) as app: # run app app.run() # test that the CLI produced the correct output text = captured.stdout.get_text() self.assertIn('Length: 4', text) self.assertIn( 'Structure: ' + ('Cc1cn(C2CC(O)C(COP(=O)([O-])OC3CC(OC3COP(=O)([O-])OC3CC(OC3COP(=O)([O-])' 'OC3CC(OC3COP(=O)([O-])[O-])n3cnc4c(N)ncnc34)n3ccc(N)nc3=O)n3cnc4c3nc(N)[nH]' 'c4=O)O2)c(=O)[nH]c1=O'), text) self.assertIn('Formula: C39', text) self.assertIn('Molecular weight: 1248.772047992', text) self.assertIn('Charge: -5', text) with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'get-properties', 'canonical_dna', 'ACGT', '--ph', '7.0' ]) as app: # run app with mock.patch.object(bpforms.BpForm, 'export', side_effect=Exception('error')): app.run() # test that the CLI produced the correct output text = captured.stdout.get_text() self.assertIn('Length: 4', text) self.assertIn('Structure: None', text) self.assertIn('Formula: None', text) self.assertIn('Molecular weight: None', text) self.assertIn('Charge: None', text) with capturer.CaptureOutput(merged=False, relay=False) as captured: with __main__.App(argv=[ 'get-properties', 'canonical_dna', 'ACGT', '--circular' ]) as app: # run app app.run() # test that the CLI produced the correct output text = captured.stdout.get_text() self.assertIn('Length: 4', text) self.assertNotIn('Structure: None', text) self.assertIn('Formula: C39', text) self.assertIn('Molecular weight: ', text) self.assertIn('Charge: -', text) self.assertEqual(captured.stderr.get_text(), '') with self.assertRaises(SystemExit): with __main__.App( argv=['get-properties', 'canonical_dna', 'ACGT[']) as app: # run app app.run() with self.assertRaisesRegex(SystemExit, '^Form is invalid'): with __main__.App(argv=[ 'get-properties', 'canonical_dna', ('ACGT' '[id: "dI" | structure: "{}" | backbone-displaced-atom: H10 ]' ).format(dI_smiles) ]) as app: # run app app.run()