Ejemplo n.º 1
0
def test_file_as_object(tmpdir):
    test_file = tmpdir.join('test.bib')
    test_file.write('''
    @article { name, author = {Max Mustermann},
        year = {2009},
        journal = {Life Journale},
        title = {la%la}
    }
    ''')
    with io.open(str(test_file), encoding='utf-8') as fp:
        parser.parse_file(fp)
    with io.open(str(test_file), encoding='utf-8') as fp:
        parser.parse_file(fp, validate=True)

    # Invalid structure
    test_file.write('''
    @article { name, author = {Max Mustermann},
        title = {la%la}
    }
    ''')
    with io.open(str(test_file), encoding='utf-8') as fp:
        parser.parse_file(fp)
    with io.open(str(test_file), encoding='utf-8') as fp:
        with pytest.raises(exceptions.InvalidStructure):
            parser.parse_file(fp, validate=True)
Ejemplo n.º 2
0
def start_parsing():

    # remove all old publication files
    for root, dirs, files in os.walk("../" + PUBLICATION_MARKDOWN_FOLDER):
        for one_file in files:
            os.unlink(root + "/" + one_file)

    arr_bib_types = get_bib_types()
    for bib_type in arr_bib_types:
        bib_url = BIBTEX_FOLDER + "/" + bib_type + ".bib"
        tmp_url = TEMP_FILE_FOLDER + "/" + bib_type + ".txt"

        # create formatted reference text
        process = subprocess.Popen('pybtex-format ' + bib_url + ' ' + tmp_url,
                                   shell=True,
                                   stdout=subprocess.PIPE)
        process.wait()

        array_text = []
        with open(tmp_url) as f:
            array_text = f.readlines()
        bibliography = parse_file(bib_url)
        for key, article in bibliography.iteritems():
            article["pub_type"] = bib_type
            article["title"] = article["title"].strip("{").strip("}")
            write_to_markdown_file(
                key, article, find_text_in_array(array_text, article['title']))
Ejemplo n.º 3
0
def test_file_as_path(tmpdir):
    test_file = tmpdir.join('test.bib')
    test_file.write('''
    @article { name, author = {Max Mustermann},
        year = {2009},
        journal = {Life Journale},
        title = {la%la}
    }
    ''')
    parser.parse_file(str(test_file))
    parser.parse_file(str(test_file), validate=True)

    # Invalid structure
    test_file.write('''
    @article { name, author = {Max Mustermann},
        title = {la%la}
    }
    ''')
    parser.parse_file(str(test_file))
    with pytest.raises(exceptions.InvalidStructure):
        parser.parse_file(str(test_file), validate=True)