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])
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'
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'
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)