import pubmed_parser as pp


def test_parsing():
    article_path = "PMC4266334.xml"
    abs_phars = pp.parse_pubmed_paragraph(article_path, all_paragraph=True,
                                          section='abs',
                                          subscpt=["", ""],
                                          supscpt=["", ""])

    body_phars = pp.parse_pubmed_paragraph(article_path, all_paragraph=True,
                                           section='body',
                                           subscpt=["", ""],
                                           supscpt=["", ""])
    assert body_phars[0]['text'] == 'In the search for metal-based chemotherapeutics with improved properties with ' \
                                    'respect to platinum-based drugs used in the clinic, ruthenium compounds have ' \
                                    'emerged as promising candidates. Ruthenium complexes have certain ' \
                                    'characteristics that make them attractive as potential chemotherapeutics for ' \
                                    'different diseases. Ruthenium compounds can easily access three different ' \
                                    'oxidation states (II, III, and possibly IV) in biological fluids. Ruthenium(III) ' \
                                    'compounds could potentially behave as pro-drugs as they can be reduced to ' \
                                    'ruthenium(II) derivatives in solid tumor masses where the low content in oxygen ' \
                                    'may act as a reducing environment. As platinum-based drugs, ruthenium compounds ' \
                                    'can exchange N and O-donor molecules with the added advantage of the possibility ' \
                                    'of forming octahedral complexes (of interest in reactions with DNA). Lastly, ' \
                                    'ruthenium derivatives probably use transferrin to accumulate into tumors due to ' \
                                    'the similarities with iron. '
    assert body_phars[3]['text'] == "We have reported that nontoxic iminophosphorane or iminophosphane (IM) compounds " \
                                    "(R3P=N-R′, IM) are useful precursors for the preparation of coordination (N," \
                                    "N−) or cyclometalated (C,N−) complexes of d8 metals (Au(III), Pd(II), " \
                                    "and Pt(II)) mono- or heterometallic (selected compounds a–g in Chart 2). "
    assert abs_phars[0]['text'] == 'A series of organometallic ruthenium(II) complexes containing iminophosphorane ' \
                                   'ligands have been synthesized and characterized. Cationic compounds with chloride ' \
                                   'as counterion are soluble in water (70–100 mg/mL). Most compounds (especially ' \
                                   'highly water-soluble 2) are more cytotoxic to a number of human cancer cell lines ' \
                                   'than cisplatin. Initial mechanistic studies indicate that the cell death type for ' \
                                   'these compounds is mainly through canonical or caspase-dependent apoptosis, ' \
                                   'nondependent on p53, and that the compounds do not interact with DNA or inhibit ' \
                                   'protease cathepsin B. In vivo experiments of 2 on MDA-MB-231 xenografts in ' \
                                   'NOD.CB17-Prkdc SCID/J mice showed an impressive tumor reduction (shrinkage) of ' \
                                   '56% after 28 days of treatment (14 doses of 5 mg/kg every other day) with low ' \
                                   'systemic toxicity. Pharmacokinetic studies showed a quick absorption of 2 in ' \
                                   'plasma with preferential accumulation in the breast tumor tissues when compared ' \
                                   'to kidney and liver, which may explain its high efficacy in vivo. '


def test_tagged_abstract_parsing():
    all_parsed = pp.parse_medline_xml("15915352.xml", subscpt=["", ""], supscpt=["", ""], year_info_only=False)
    assert all_parsed[0]['abstract'] == "Carbamazepine (CBZ) undergoes biotransformation by CYP3A4 and CYP2C8, " \
                                        "and glucuronide conjugation. There has been no clear demonstration to reveal " \
                                        "the role of glucuronidation in the disposition of CBZ. We evaluated the " \
                                        "effect of probenecid, a UDP-glucuronosyltransferase inhibitor, " \
                                        "on the pharmacokinetics of CBZ in humans. In a randomized, open-label, " \
                                        "two-way crossover study, ten healthy male subjects were treated twice daily " \
                                        "for 10 days with 500 mg probenecid or with a matched placebo. On day 6, " \
                                        "a single dose of 200 mg CBZ was administered orally. Concentrations of CBZ " \
                                        "and CBZ 10,11-epoxide (CBZ-E) in plasma and urine were measured. Probenecid " \
                                        "decreased the area under the plasma concentration-time curve (AUC) of CBZ " \
                                        "from 1253.9 micromol h/l to 1020.7 micromol h/l (P < 0.001) while increasing " \
                                        "that of CBZ-E from 137.6 micromol h/l to 183.5 micromol h/l (P = 0.033). The " \
                                        "oral clearance of CBZ was increased by probenecid by 26% (90% confidence " \
                                        "interval, 17-34%; P < 0.001). Probenecid increased the AUC ratio of " \
                                        "CBZ-E/CBZ from 0.11 to 0.16 (P < 0.001). However, probenecid had minimal " \
                                        "effect on the recovery of the conjugated and free forms of CBZ and CBZ-E in " \
                                        "urine. Although probenecid showed a minimal effect on the glucuronidation of " \
                                        "CBZ and CBZ-E, it increased CBZ biotransformation to CBZ-E, most likely " \
                                        "reflecting the induction of CYP3A4 and CYP2C8 activities, in humans. These " \
                                        "results demonstrate that glucuronide conjugation plays a minor role in the " \
                                        "metabolism of CBZ and CBZ-E in humans, and that probenecid has an inducing " \
                                        "effect on the disposition of CBZ."



import pubmed_parser as pp


def test_parsing():
    article_path = "PMC4266334.xml"
    abs_phars = pp.parse_pubmed_paragraph(article_path, all_paragraph=True,
                                          section='abs',
                                          subscpt=["", ""],
                                          supscpt=["", ""])

    body_phars = pp.parse_pubmed_paragraph(article_path, all_paragraph=True,
                                           section='body',
                                           subscpt=["", ""],
                                           supscpt=["", ""])
    assert body_phars[0]['text'] == 'In the search for metal-based chemotherapeutics with improved properties with ' \
                                    'respect to platinum-based drugs used in the clinic, ruthenium compounds have ' \
                                    'emerged as promising candidates. Ruthenium complexes have certain ' \
                                    'characteristics that make them attractive as potential chemotherapeutics for ' \
                                    'different diseases. Ruthenium compounds can easily access three different ' \
                                    'oxidation states (II, III, and possibly IV) in biological fluids. Ruthenium(III) ' \
                                    'compounds could potentially behave as pro-drugs as they can be reduced to ' \
                                    'ruthenium(II) derivatives in solid tumor masses where the low content in oxygen ' \
                                    'may act as a reducing environment. As platinum-based drugs, ruthenium compounds ' \
                                    'can exchange N and O-donor molecules with the added advantage of the possibility ' \
                                    'of forming octahedral complexes (of interest in reactions with DNA). Lastly, ' \
                                    'ruthenium derivatives probably use transferrin to accumulate into tumors due to ' \
                                    'the similarities with iron. '
    assert body_phars[3]['text'] == "We have reported that nontoxic iminophosphorane or iminophosphane (IM) compounds " \
                                    "(R3P=N-R′, IM) are useful precursors for the preparation of coordination (N," \
                                    "N−) or cyclometalated (C,N−) complexes of d8 metals (Au(III), Pd(II), " \
                                    "and Pt(II)) mono- or heterometallic (selected compounds a–g in Chart 2). "
    assert abs_phars[0]['text'] == 'A series of organometallic ruthenium(II) complexes containing iminophosphorane ' \
                                   'ligands have been synthesized and characterized. Cationic compounds with chloride ' \
                                   'as counterion are soluble in water (70–100 mg/mL). Most compounds (especially ' \
                                   'highly water-soluble 2) are more cytotoxic to a number of human cancer cell lines ' \
                                   'than cisplatin. Initial mechanistic studies indicate that the cell death type for ' \
                                   'these compounds is mainly through canonical or caspase-dependent apoptosis, ' \
                                   'nondependent on p53, and that the compounds do not interact with DNA or inhibit ' \
                                   'protease cathepsin B. In vivo experiments of 2 on MDA-MB-231 xenografts in ' \
                                   'NOD.CB17-Prkdc SCID/J mice showed an impressive tumor reduction (shrinkage) of ' \
                                   '56% after 28 days of treatment (14 doses of 5 mg/kg every other day) with low ' \
                                   'systemic toxicity. Pharmacokinetic studies showed a quick absorption of 2 in ' \
                                   'plasma with preferential accumulation in the breast tumor tissues when compared ' \
                                   'to kidney and liver, which may explain its high efficacy in vivo. '


def test_tagged_abstract_parsing():
    all_parsed = pp.parse_medline_xml("15915352.xml", subscpt=["", ""], supscpt=["", ""], year_info_only=False)
    assert all_parsed[0]['abstract'] == "Carbamazepine (CBZ) undergoes biotransformation by CYP3A4 and CYP2C8, " \
                                        "and glucuronide conjugation. There has been no clear demonstration to reveal " \
                                        "the role of glucuronidation in the disposition of CBZ. We evaluated the " \
                                        "effect of probenecid, a UDP-glucuronosyltransferase inhibitor, " \
                                        "on the pharmacokinetics of CBZ in humans. In a randomized, open-label, " \
                                        "two-way crossover study, ten healthy male subjects were treated twice daily " \
                                        "for 10 days with 500 mg probenecid or with a matched placebo. On day 6, " \
                                        "a single dose of 200 mg CBZ was administered orally. Concentrations of CBZ " \
                                        "and CBZ 10,11-epoxide (CBZ-E) in plasma and urine were measured. Probenecid " \
                                        "decreased the area under the plasma concentration-time curve (AUC) of CBZ " \
                                        "from 1253.9 micromol h/l to 1020.7 micromol h/l (P < 0.001) while increasing " \
                                        "that of CBZ-E from 137.6 micromol h/l to 183.5 micromol h/l (P = 0.033). The " \
                                        "oral clearance of CBZ was increased by probenecid by 26% (90% confidence " \
                                        "interval, 17-34%; P < 0.001). Probenecid increased the AUC ratio of " \
                                        "CBZ-E/CBZ from 0.11 to 0.16 (P < 0.001). However, probenecid had minimal " \
                                        "effect on the recovery of the conjugated and free forms of CBZ and CBZ-E in " \
                                        "urine. Although probenecid showed a minimal effect on the glucuronidation of " \
                                        "CBZ and CBZ-E, it increased CBZ biotransformation to CBZ-E, most likely " \
                                        "reflecting the induction of CYP3A4 and CYP2C8 activities, in humans. These " \
                                        "results demonstrate that glucuronide conjugation plays a minor role in the " \
                                        "metabolism of CBZ and CBZ-E in humans, and that probenecid has an inducing " \
                                        "effect on the disposition of CBZ."


