def main(args): if not args.narrative_ref: print( "Must include a Narrative object reference in the format XXX/YYY (these are the numbers in the usual Narrative URL)" ) return 1 if not args.outfile: print("Must include an output file for exporting the Narrative!") return 1 outfile = args.outfile if not outfile.lower().endswith(".html"): outfile = outfile + ".html" exporter = NarrativeExporter() try: exporter.export_narrative(args.narrative_ref, outfile) except PermissionsError: print("The Narrative at reference " + args.narrative_ref + " does not appear to be public!") return 1 except Exception as e: print("An error occurred while exporting your Narrative:") print(str(e)) return 1
class NarrativeExportTesting(unittest.TestCase): @classmethod @mock.patch('biokbase.narrative.exporter.exporter.NarrativeIO') def setUpClass(self, mock_io): mock_io.return_value.test_connection.return_value = "" mock_io.return_value.read_narrative = mock_read_narrative self.exporter = NarrativeExporter() @classmethod def tearDownClass(self): # delete generated file if os.path.isfile(output_file): os.remove(output_file) def test_export_good(self): self.exporter.export_narrative(test_narrative_ref, output_file) self.assertTrue(os.path.isfile(output_file)) def test_export_bad(self): with self.assertRaises(ValueError) as err: self.exporter.export_narrative(bad_narrative_ref, output_file) def test_export_private(self): with self.assertRaises(PermissionsError) as err: self.exporter.export_narrative(private_narrative_ref, output_file)
class NarrativeExportTesting(unittest.TestCase): @classmethod @mock.patch("biokbase.narrative.exporter.exporter.NarrativeIO") def setUpClass(self, mock_io): mock_io.return_value.test_connection.return_value = "" mock_io.return_value.read_narrative = mock_read_narrative self.exporter = NarrativeExporter() @classmethod def tearDownClass(self): # delete generated file if os.path.isfile(output_file): os.remove(output_file) def test_export_good(self): self.exporter.export_narrative(test_narrative_ref, output_file) self.assertTrue(os.path.isfile(output_file)) def test_export_bad(self): with self.assertRaises(ValueError) as err: self.exporter.export_narrative(bad_narrative_ref, output_file) def test_export_private(self): with self.assertRaises(PermissionsError) as err: self.exporter.export_narrative(private_narrative_ref, output_file)
def main(args): if not args.narrative_ref: print("Must include a Narrative object reference in the format XXX/YYY (these are the numbers in the usual Narrative URL)") return 1 if not args.outfile: print("Must include an output file for exporting the Narrative!") return 1 outfile = args.outfile if not outfile.lower().endswith(".html"): outfile = outfile + ".html" exporter = NarrativeExporter() try: exporter.export_narrative(args.narrative_ref, outfile) except PermissionsError: print("The Narrative at reference " + args.narrative_ref + " does not appear to be public!") return 1 except Exception as e: print("An error occurred while exporting your Narrative:") print(str(e)) return 1