コード例 #1
0
ファイル: test_utils.py プロジェクト: wbrandenburger/papis
def test_extension():
    docs = [
        [tests.create_random_pdf(), "pdf"],
        [tests.create_random_pdf(), "pdf"],
        [tests.create_random_file(), "data"],
        [tests.create_random_epub(), "epub"],
        [tests.create_random_file(suffix='.yaml'), "yaml"],
        [tests.create_random_file(suffix='.text'), "text"],
    ]
    for d in docs:
        assert(get_document_extension(d[0]) == d[1])
コード例 #2
0
    def test_get_file_name(self):
        path = tempfile.mktemp(prefix='papis-get_name-')
        open(path, 'w+').close()

        assert (papis.config.get('file-name') is None)
        filename = get_file_name(dict(title='blah'), path, suffix='3')
        assert (re.match(r'^papis-get-name-.*\.data$', filename) is not None)

        papis.config.set('file-name',
                         '{doc[title]} {doc[author]} {doc[yeary]}')

        filename = get_file_name(dict(title='blah'), path, suffix='2')
        assert filename == 'blah-2.data'

        filename = get_file_name(dict(title='b' * 200), path, suffix='2')
        assert filename == 'b' * 150 + '-2.data'

        filename = get_file_name(dict(title='blah'),
                                 create_random_pdf(suffix='.pdf'),
                                 suffix='2')
        assert filename == 'blah-2.pdf'

        filename = get_file_name(dict(title='blah'),
                                 create_random_pdf(),
                                 suffix='2')
        assert filename == 'blah-2.pdf'

        filename = get_file_name(dict(title='blah'),
                                 create_random_file(suffix='.yaml'),
                                 suffix='2')
        assert filename == 'blah-2.yaml'
コード例 #3
0
ファイル: test_add.py プロジェクト: wbrandenburger/papis
    def test_get_file_name(self):
        pdf = create_random_pdf(suffix='.pdf')
        path = create_random_file(prefix='papis-get_name-')

        assert(papis.config.utils.get('add-file-name') is None)
        filename = get_file_name(dict(title='blah'), path, suffix='3')
        assert(re.match(r'^papis-get-name-.*\.data$', filename) is not None)
        # With suffix
        filename = get_file_name(dict(title='blah'), pdf, suffix='3')
        assert(len(re.split('[.]pdf', filename)) == 2)
        # Without suffix
        filename = get_file_name(dict(title='blah'), pdf)
        assert(len(re.split('[.]pdf', filename)) == 2)

        papis.config.utils.set(
            'add-file-name',
            '{doc[title]} {doc[author]} {doc[yeary]}'
        )

        filename = get_file_name(dict(title='blah'), path, suffix='2')
        assert filename == 'blah-2.data'

        filename = get_file_name(dict(title='b' * 200), path, suffix='2')
        assert filename == 'b' * 150 + '-2.data'

        filename = get_file_name(
            dict(title='blah'), create_random_pdf(suffix='.pdf'), suffix='2'
        )
        assert filename == 'blah-2.pdf'

        filename = get_file_name(
            dict(title='blah'), create_random_pdf(), suffix='2'
        )
        assert filename == 'blah-2.pdf'

        filename = get_file_name(
            dict(title='blah'), create_random_file(suffix='.yaml'), suffix='2'
        )
        assert filename == 'blah-2.yaml'
コード例 #4
0
def test_new() -> None:
    N = 10
    files = [create_random_file(suffix='.' + str(i)) for i in range(N)]
    tmp = os.path.join(tempfile.mkdtemp(), 'doc')
    doc = new(tmp, {'author': 'hello'}, files)
    assert (os.path.exists(doc.get_main_folder()))
    assert (doc.get_main_folder() == tmp)
    assert (len(doc['files']) == N)
    assert (len(doc.get_files()) == N)
    for i in range(N):
        assert (doc['files'][i].endswith(str(i)))
        assert (not os.path.exists(doc['files'][i]))
        assert (os.path.exists(doc.get_files()[i]))

    tmp = os.path.join(tempfile.mkdtemp(), 'doc')
    doc = new(tmp, {'author': 'hello'}, [])
    assert (os.path.exists(doc.get_main_folder()))
    assert (doc.get_main_folder() == tmp)
    assert (len(doc['files']) == 0)
    assert (len(doc.get_files()) == 0)