# Path: pubs/content.py
# class UnableToDecodeTextFile(Exception):
#     def __init__(self, path):
#     def __str__(self):
# def _check_system_path_exists(path, fail=True):
# def _check_system_path_is(nature, path, fail=True):
# def system_path(path):
# def _open(path, mode):
# def check_file(path, fail=True):
# def check_directory(path, fail=True):
# def read_text_file(filepath, fail=True):
# def read_binary_file(filepath, fail=True):
# def remove_file(filepath):
# def write_file(filepath, data, mode='w'):
# def content_type(path):
# def url_exists(url):
# def check_content(path):
# def _get_byte_url_content(path, ui=None):
# def _dump_byte_url_content(source, target):
# def get_content(path, ui=None):
# def move_content(source, target, overwrite=False):
# def copy_content(source, target, overwrite=False):
# 
# Path: pubs/databroker.py
# class DataBroker(object):
#     def __init__(self, pubsdir, docsdir, create=False):
#     def close(self):
#     def pull_cache(self, name):
#     def push_cache(self, name, data):
#     def pull_metadata(self, citekey):
#     def pull_bibentry(self, citekey):
#     def push_metadata(self, citekey, metadata):
#     def push_bibentry(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def citekeys(self):
#     def listing(self, filestats=True):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
#     def _notepath(self, citekey, extension):
#     def real_notepath(self, citekey, extension):
#     def remove_note(self, citekey, extension, silent=True):
#     def rename_note(self, old_citekey, new_citekey, extension):
# 
# Path: pubs/datacache.py
# class CacheEntry(object):
# class CacheEntrySet(object):
# class DataCache(object):
#     def __init__(self, data, timestamp):
#     def __init__(self, databroker, name):
#     def entries(self):
#     def flush(self, force=False):
#     def pull(self, citekey):
#     def push(self, citekey, data):
#     def push_to_cache(self, citekey, data):
#     def remove_from_cache(self, citekey):
#     def _try_pull_cache(self):
#     def _is_outdated(self, citekey):
#     def __init__(self, pubsdir, docsdir, create=False):
#     def close(self):
#     def databroker(self):
#     def metacache(self):
#     def bibcache(self):
#     def _create(self):
#     def flush_cache(self, force=False):
#     def pull_metadata(self, citekey):
#     def pull_bibentry(self, citekey):
#     def push_metadata(self, citekey, metadata):
#     def push_bibentry(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def citekeys(self):
#     def listing(self, filestats=True):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
#     def real_notepath(self, citekey, extension):
#     def remove_note(self, citekey, extension, silent=True):
#     def rename_note(self, old_citekey, new_citekey, extension):
# 
# Path: pubs/endecoder.py
#     BP_ID_KEY = 'ID'
#     BP_ENTRYTYPE_KEY = 'ENTRYTYPE'
#     BP_ID_KEY = 'id'
#     BP_ENTRYTYPE_KEY = 'type'
# BIBFIELD_ORDER = ['author', 'title', 'journal', 'institution', 'publisher',
#                   'year', 'month', 'number', 'volume', 'pages', 'url', 'link',
#                   'doi', 'note', 'abstract']
# def sanitize_citekey(record):
# def customizations(record):
#         def __init__(self, error_msg, bibdata):
#     def encode_metadata(self, metadata):
#     def decode_metadata(self, metadata_raw):
#     def encode_bibdata(self, bibdata, ignore_fields=[]):
#     def _entry_to_bp_entry(self, key, entry, ignore_fields=[]):
#     def decode_bibdata(self, bibstr):
#     def _format_parsing_error(cls, e):
# class EnDecoder(object):
#     class BibDecodingError(Exception):


import unittest
import os
import dotdot
import fake_env
import str_fixtures
from pubs import content, databroker, datacache
from pubs import endecoder
            with self.assertRaises(IOError):
                db.pull_metadata('citekey')

            db.add_doc('Larry99', 'docsdir://Page99.pdf')
            self.assertTrue(content.check_file('testrepo/doc/Page99.pdf', fail=False))
            self.assertTrue(content.check_file('testrepo/doc/Larry99.pdf', fail=False))

            db.remove_doc('docsdir://Page99.pdf')

    def test_push_pull_cache(self):
        db = databroker.DataBroker('tmp', 'tmp/doc', create=True)
        data_in = {'a': 1}
        db.push_cache('meta', data_in)
        data_out = db.pull_cache('meta')
        self.assertEqual(data_in, data_out)

    def test_pull_cache_fails_on_version_mismatch(self):
        db = databroker.DataBroker('tmp', 'tmp/doc', create=True)
        data_in = {'a': 1}
        db.push_cache('meta', data_in)
        ver = databroker.__version__
        databroker.__version__ = '0.0.0'
        try:
            with self.assertRaises(ValueError):
                db.pull_cache('meta')
        finally:
            databroker.__version__ = ver


if __name__ == '__main__':

# Path: pubs/content.py
# class UnableToDecodeTextFile(Exception):
#     def __init__(self, path):
#     def __str__(self):
# def _check_system_path_exists(path, fail=True):
# def _check_system_path_is(nature, path, fail=True):
# def system_path(path):
# def _open(path, mode):
# def check_file(path, fail=True):
# def check_directory(path, fail=True):
# def read_text_file(filepath, fail=True):
# def read_binary_file(filepath, fail=True):
# def remove_file(filepath):
# def write_file(filepath, data, mode='w'):
# def content_type(path):
# def url_exists(url):
# def check_content(path):
# def _get_byte_url_content(path, ui=None):
# def _dump_byte_url_content(source, target):
# def get_content(path, ui=None):
# def move_content(source, target, overwrite=False):
# def copy_content(source, target, overwrite=False):
# 
# Path: pubs/databroker.py
# class DataBroker(object):
#     def __init__(self, pubsdir, docsdir, create=False):
#     def close(self):
#     def pull_cache(self, name):
#     def push_cache(self, name, data):
#     def pull_metadata(self, citekey):
#     def pull_bibentry(self, citekey):
#     def push_metadata(self, citekey, metadata):
#     def push_bibentry(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def citekeys(self):
#     def listing(self, filestats=True):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
#     def _notepath(self, citekey, extension):
#     def real_notepath(self, citekey, extension):
#     def remove_note(self, citekey, extension, silent=True):
#     def rename_note(self, old_citekey, new_citekey, extension):
# 
# Path: pubs/datacache.py
# class CacheEntry(object):
# class CacheEntrySet(object):
# class DataCache(object):
#     def __init__(self, data, timestamp):
#     def __init__(self, databroker, name):
#     def entries(self):
#     def flush(self, force=False):
#     def pull(self, citekey):
#     def push(self, citekey, data):
#     def push_to_cache(self, citekey, data):
#     def remove_from_cache(self, citekey):
#     def _try_pull_cache(self):
#     def _is_outdated(self, citekey):
#     def __init__(self, pubsdir, docsdir, create=False):
#     def close(self):
#     def databroker(self):
#     def metacache(self):
#     def bibcache(self):
#     def _create(self):
#     def flush_cache(self, force=False):
#     def pull_metadata(self, citekey):
#     def pull_bibentry(self, citekey):
#     def push_metadata(self, citekey, metadata):
#     def push_bibentry(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def citekeys(self):
#     def listing(self, filestats=True):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
#     def real_notepath(self, citekey, extension):
#     def remove_note(self, citekey, extension, silent=True):
#     def rename_note(self, old_citekey, new_citekey, extension):
# 
# Path: pubs/endecoder.py
#     BP_ID_KEY = 'ID'
#     BP_ENTRYTYPE_KEY = 'ENTRYTYPE'
#     BP_ID_KEY = 'id'
#     BP_ENTRYTYPE_KEY = 'type'
# BIBFIELD_ORDER = ['author', 'title', 'journal', 'institution', 'publisher',
#                   'year', 'month', 'number', 'volume', 'pages', 'url', 'link',
#                   'doi', 'note', 'abstract']
# def sanitize_citekey(record):
# def customizations(record):
#         def __init__(self, error_msg, bibdata):
#     def encode_metadata(self, metadata):
#     def decode_metadata(self, metadata_raw):
#     def encode_bibdata(self, bibdata, ignore_fields=[]):
#     def _entry_to_bp_entry(self, key, entry, ignore_fields=[]):
#     def decode_bibdata(self, bibstr):
#     def _format_parsing_error(cls, e):
# class EnDecoder(object):
#     class BibDecodingError(Exception):


# Path: tests/test_databroker.py
import unittest
import os
import dotdot
import fake_env
import str_fixtures
from pubs import content, databroker, datacache
from pubs import endecoder

            with self.assertRaises(IOError):
                db.pull_metadata('citekey')

            db.add_doc('Larry99', 'docsdir://Page99.pdf')
            self.assertTrue(content.check_file('testrepo/doc/Page99.pdf', fail=False))
            self.assertTrue(content.check_file('testrepo/doc/Larry99.pdf', fail=False))

            db.remove_doc('docsdir://Page99.pdf')

    def test_push_pull_cache(self):
        db = databroker.DataBroker('tmp', 'tmp/doc', create=True)
        data_in = {'a': 1}
        db.push_cache('meta', data_in)
        data_out = db.pull_cache('meta')
        self.assertEqual(data_in, data_out)

    def test_pull_cache_fails_on_version_mismatch(self):
        db = databroker.DataBroker('tmp', 'tmp/doc', create=True)
        data_in = {'a': 1}
        db.push_cache('meta', data_in)
        ver = databroker.__version__
        databroker.__version__ = '0.0.0'
        try:
            with self.assertRaises(ValueError):
                db.pull_cache('meta')
        finally:
            databroker.__version__ = ver


if __name__ == '__main__':

    unittest.main(verbosity=2)