Exemple #1
0
def define_tests_for_mcdplibs(context):
    """
        Looks for directories called *.mcdplib in the root of the package.
        
        It also looks for the files *.mcdp_tests.yaml inside.
    """
    librarian = get_test_librarian()

    for libname in enumerate_test_libraries():

        c2 = context.child(libname, extra_report_keys=dict(libname=libname))

        for spec_name in specs:
            c3 = c2.child(spec_name)
            c3.comp_dynamic(mcdplib_test_setup_spec,
                            spec_name=spec_name,
                            libname=libname)

        #         c2.child('ndp').comp_dynamic(mcdplib_test_setup_nameddps, libname=libname)
        #         c2.child('poset').comp_dynamic(mcdplib_test_setup_posets, libname=libname)
        #         c2.child('primitivedp').comp_dynamic(mcdplib_test_setup_primitivedps, libname=libname)
        #         c2.child('source_mcdp').comp_dynamic(mcdplib_test_setup_sources, libname=libname)
        #         c2.child('value').comp_dynamic(mcdplib_test_setup_value, libname=libname)
        #         c2.child('template').comp_dynamic(mcdplib_test_setup_template, libname=libname)

        path = librarian.libraries[libname]['path']
        makefile = os.path.join(path, 'Makefile')
        if os.path.exists(makefile):
            c2.comp(mcdplib_run_make, mcdplib=path)
Exemple #2
0
def enumerate_test_libraries():
    """ 
        Libraries on which we need to run tests. 
    
    Returns list of (bigpath, short_name, path) """
    librarian = get_test_librarian()

    found = []

    libraries = librarian.get_libraries()

    for short in list(libraries):
        data = libraries[short]
        path = data['path']
        f = os.path.join(path, '.mcdp_test_ignore')
        if os.path.exists(f):
            continue

        found.append(short)

    i, n = get_test_index()
    if n == 1:
        uselibs = found
    else:
        assert n > 1
        # 0 only gets the basic tests
        if i == 0:
            return []
        else:
            n_effective = n - 1
            i_effective = i - 1
            assert 0 <= i_effective < n_effective

            uselibs = []
            buckets = [[] for _ in range(n_effective)]

            for j, libname in enumerate(found):
                #do = j % n_effective == i_effective
                which = int(math.floor((float(j) / len(found)) * n_effective))

                assert 0 <= which < n_effective, (j, which, n_effective)
                buckets[which].append(libname)


#                 do = math.floor((j - 1) / n_effective) == i_effective
            for libname in found:
                do = libname in buckets[i_effective]
                if do:
                    uselibs.append(libname)
                    s = 'will do'
                else:
                    s = 'skipped because of parallelism'
                logger.debug('%20s: %s' % (libname, s))

            ntot = sum(len(_) for _ in buckets)
            assert ntot == len(found)

    return uselibs
Exemple #3
0
def render_book(src_dirs,
                generate_pdf,
                data,
                realpath,
                main_file,
                use_mathjax,
                out_part_basename,
                raise_errors,
                filter_soup=None,
                extra_css=None,
                symbols=None):
    from mcdp_docs.pipeline import render_complete

    librarian = get_test_librarian()
    # XXX: these might need to be changed
    if not MCDPConstants.softy_mode:
        librarian.find_libraries('.')

    load_library_hooks = [librarian.load_library]
    library = MCDPLibrary(load_library_hooks=load_library_hooks)

    for src_dir in src_dirs:
        library.add_search_dir(src_dir)

    d = tempfile.mkdtemp()
    library.use_cache_dir(d)

    def filter_soup0(soup, library):
        if filter_soup is not None:
            filter_soup(soup=soup, library=library)
        add_edit_links(soup, realpath)

    try:
        html_contents = render_complete(library=library,
                                        s=data,
                                        raise_errors=raise_errors,
                                        realpath=realpath,
                                        use_mathjax=use_mathjax,
                                        symbols=symbols,
                                        generate_pdf=generate_pdf,
                                        filter_soup=filter_soup0)
    except DPSyntaxError as e:
        msg = 'Could not compile %s' % realpath
        raise_wrapped(DPSyntaxError, e, msg, compact=True)

    doc = get_minimal_document(html_contents,
                               add_markdown_css=True,
                               extra_css=extra_css)
    dirname = main_file + '.parts'
    if dirname and not os.path.exists(dirname):
        try:
            os.makedirs(dirname)
        except:
            pass
    fn = os.path.join(dirname, '%s.html' % out_part_basename)
    write_data_to_file(doc, fn)

    return html_contents
Exemple #4
0
def render_book(src_dir,
                docname,
                generate_pdf,
                main_file,
                out_part_basename,
                filter_soup=None,
                extra_css=None):
    from mcdp_docs.pipeline import render_complete

    librarian = get_test_librarian()
    librarian.find_libraries('.')

    load_library_hooks = [librarian.load_library]
    library = MCDPLibrary(load_library_hooks=load_library_hooks)
    library.add_search_dir(src_dir)
    #
    #     data = dict(path=dirname, library=l)
    #     l.library_name = library_name
    #
    #     library = librarian.load_library(libname)
    #
    #     l = library.load_library(libname)

    d = tempfile.mkdtemp()
    library.use_cache_dir(d)

    basename = docname + '.' + MCDPConstants.ext_doc_md
    f = library._get_file_data(basename)
    data = f['data']
    realpath = f['realpath']

    def filter_soup0(soup, library):
        if filter_soup is not None:
            filter_soup(soup=soup, library=library)
        add_edit_links(soup, realpath)

    html_contents = render_complete(library=library,
                                    s=data,
                                    raise_errors=True,
                                    realpath=realpath,
                                    generate_pdf=generate_pdf,
                                    filter_soup=filter_soup0)

    doc = get_minimal_document(html_contents,
                               add_markdown_css=True,
                               extra_css=extra_css)
    dirname = main_file + '.parts'
    if dirname and not os.path.exists(dirname):
        try:
            os.makedirs(dirname)
        except:
            pass
    fn = os.path.join(dirname, '%s.html' % out_part_basename)
    with open(fn, 'w') as f:
        f.write(doc)

    return (('unused', docname), html_contents)
Exemple #5
0
def get_test_library(libname):
    assert isinstance(libname,
                      str) and not MCDPConstants.library_extension in libname
    librarian = get_test_librarian()
    library = librarian.load_library(libname)

    d = get_mcdp_tmp_dir()
    prefix = 'mcdp_library_tests_get_test_library_'
    d = tempfile.mkdtemp(dir=d, prefix=prefix)

    library.use_cache_dir(d)
    # XXX: this does not erase the directory
    return library
Exemple #6
0
def testing_includes(libname):
    librarian = get_test_librarian()
    return libname in librarian.get_libraries()
Exemple #7
0
def render_book(
    src_dirs,
    generate_pdf,
    data,
    realpath,
    use_mathjax,
    raise_errors,
    filter_soup=None,
    symbols=None,
    ignore_ref_errors=False,
):
    """ Returns an AugmentedResult(str) """
    res = AugmentedResult()
    from mcdp_docs.pipeline import render_complete

    librarian = get_test_librarian()
    # XXX: these might need to be changed
    if not MCDPConstants.softy_mode:
        for src_dir in src_dirs:
            librarian.find_libraries(src_dir)

    load_library_hooks = [librarian.load_library]
    library_ = MCDPLibrary(load_library_hooks=load_library_hooks)

    for src_dir in src_dirs:
        library_.add_search_dir(src_dir)

    d = tempfile.mkdtemp()
    library_.use_cache_dir(d)

    location = LocalFile(realpath)

    # print('location:\n%s' % location)

    def filter_soup0(soup, library):
        if filter_soup is not None:
            filter_soup(soup=soup, library=library)
        add_edit_links2(soup, location)
        add_last_modified_info(soup, location)

    try:
        html_contents = render_complete(library=library_,
                                        s=data,
                                        raise_errors=raise_errors,
                                        realpath=realpath,
                                        use_mathjax=use_mathjax,
                                        symbols=symbols,
                                        generate_pdf=generate_pdf,
                                        filter_soup=filter_soup0,
                                        location=location,
                                        res=res,
                                        ignore_ref_errors=ignore_ref_errors)
    except DPSyntaxError as e:
        msg = 'Could not compile %s' % realpath
        location0 = LocationInString(e.where, location)
        res.note_error(msg, locations=location0)
        fail = "<p>This file could not be compiled</p>"
        res.set_result(fail)
        return res
        # raise_wrapped(DPSyntaxError, e, msg, compact=True)

    if False:  # write minimal doc
        doc = get_minimal_document(html_contents,
                                   add_markdown_css=True,
                                   extra_css=extra_css)
        dirname = main_file + '.parts'
        if dirname and not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except:
                pass
        fn = os.path.join(dirname, '%s.html' % out_part_basename)
        write_data_to_file(doc, fn)

    res.set_result(html_contents)
    return res