示例#1
0
def test_complete_pcc_relnodes_have_ns_children():
    """All relation nodes in all PCC files have only nucleii and/or satellites
    as children.
    """
    debug = False
    okay = 0.0
    fail = 0.0
    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        filename = os.path.basename(rfile)
        try:
            rst_tree = rstc.RSTTree(rfile, debug=debug)
            if relnodes_have_ns_children(rst_tree, debug=debug):
                okay += 1
            else:
                fail += 1
                logging.log(
                    logging.WARN, "File '{}' has bad relname children".format(
                        os.path.basename(rfile)))

        except TooManyChildrenError as e:
            pass

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "\n{0}% of parsed PCC files have  only relname->N/S parent/child relations ({1} of {2})".format(success_rate, okay, okay+fail)

    debug = True
    okay = 0.0
    fail = 0.0
    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        filename = os.path.basename(rfile)
        try:
            rst_tree = rstc.RSTTree(rfile, debug=debug)
            if relnodes_have_ns_children(rst_tree, debug=debug):
                okay += 1
            else:
                relnodes_have_ns_children(rst_tree, debug=debug)

                fail += 1
                logging.log(
                    logging.WARN,
                    "File '{}' has bad relname children in debug-mode".format(
                        os.path.basename(rfile)))

        except TooManyChildrenError as e:
            pass

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "\n{0}% of debug-parsed PCC files have  only relname->N/S parent/child relations ({1} of {2})".format(success_rate, okay, okay+fail)
示例#2
0
def test_complete_pcc_no_double_ns():
    """There is no PCC file in which a nucleus/satellite has a nucleus or
    satellite as a child.
    """
    okay = 0.0
    fail = 0.0
    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        filename = os.path.basename(rfile)
        try:
            rst_tree = rstc.RSTTree(rfile)
            if no_double_ns(rst_tree.tree, filename):
                okay += 1
            else:
                fail += 1

                logging.log(
                    logging.WARN, "File '{}' has N/S->N/S parent/child".format(
                        os.path.basename(rfile)))

        except TooManyChildrenError as e:
            pass

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "\n{0}% of parsed PCC files have no N/S->N/S parent/child ({1} of {2})".format(success_rate, okay, okay+fail)

    okay = 0.0
    fail = 0.0
    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        filename = os.path.basename(rfile)
        try:
            rst_tree = rstc.RSTTree(rfile)
            if no_double_ns(rst_tree.tree, filename, debug=True):
                okay += 1
            else:
                fail += 1

                logging.log(
                    logging.WARN,
                    "File '{}' has N/S->N/S parent/child in debug mode".format(
                        os.path.basename(rfile)))

        except TooManyChildrenError as e:
            pass

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "\n{0}% of debug-parsed PCC files have no N/S->N/S parent/child ({1} of {2})".format(success_rate, okay, okay+fail)
示例#3
0
def test_complete_pcc_no_span_nodes():
    """There are no 'span' nodes in any PCC file."""
    okay = 0.0
    fail = 0.0

    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        filename = os.path.basename(rfile)
        try:
            rst_tree = rstc.RSTTree(rfile)
            if no_span_nodes(rst_tree.tree, debug=rst_tree.debug):
                okay += 1
            else:
                fail += 1
                logging.log(
                    logging.WARN, "File '{}' has bad span nodes".format(
                        os.path.basename(rfile)))

        except TooManyChildrenError as e:
            pass

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "\n{0}% of parsed PCC files have no bad span nodes ({1} of {2})".format(success_rate, okay, okay+fail)

    okay = 0.0
    fail = 0.0
    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        filename = os.path.basename(rfile)
        try:
            rst_tree = rstc.RSTTree(rfile, debug=True)
            if no_span_nodes(rst_tree.tree, debug=rst_tree.debug):
                okay += 1
            else:
                fail += 1
                logging.log(
                    logging.WARN,
                    "File '{}' has bad span nodes in debug mode".format(
                        os.path.basename(rfile)))

        except TooManyChildrenError as e:
            pass

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "\n{0}% of debug-parsed PCC files have no bad span nodes ({1} of {2})".format(success_rate, okay, okay+fail)
示例#4
0
def test_parse_complete_pcc():
    """All *.rs3 files can be parsed into RSTTree instances."""
    okay = 0.0
    fail = 0.0
    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        try:
            x = rstc.RSTTree(rfile)
            okay += 1
        except Exception as e:
            logging.log(
                logging.WARN,
                "File '{0}' can't be parsed into an RSTTree: {1}".format(
                    os.path.basename(rfile), e))
            fail += 1

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "{0}% of PCC files could be parsed ({1} of {2})".format(success_rate, okay, okay+fail)
示例#5
0
def test_complete_pcc_edu_order():
    """The order of EDUs in all generated RSTTrees is the same as in the
    original *.rs3 files.
    """
    okay = 0.0
    fail = 0.0
    for i, rfile in enumerate(glob.glob(os.path.join(PCC_RS3_DIR, '*.rs3'))):
        try:
            rst_tree = rstc.RSTTree(rfile)
            if rst_tree.edu_strings == rst_tree.tree.leaves():
                okay += 1
            else:
                fail += 1

                logging.log(
                    logging.WARN, "EDU order in file '{}' is wrong!".format(
                        os.path.basename(rfile)))

        except TooManyChildrenError as e:
            pass

    success_rate = okay / (okay + fail) * 100
    assert success_rate == 100, \
        "\n{0}% of parsed PCC files have correct EDU order ({1} of {2})".format(success_rate, okay, okay+fail)