# Path: datafs/_compat.py
# def open_filelike(filelike, mode='r'):
# 
# Path: tests/resources.py
# @contextmanager
# def prep_manager(mgr_name, table_name='my-new-data-table'):
# 
#     if mgr_name == 'mongo':
# 
#         manager_mongo = MongoDBManager(
#             database_name='MyDatabase',
#             table_name=table_name)
# 
#         manager_mongo.create_archive_table(
#             table_name,
#             raise_on_err=False)
# 
#         try:
#             yield manager_mongo
# 
#         finally:
#             manager_mongo.delete_table(
#                 table_name,
#                 raise_on_err=False)
# 
#     elif mgr_name == 'dynamo':
# 
#         manager_dynamo = DynamoDBManager(
#             table_name,
#             session_args={
#                 'aws_access_key_id': "access-key-id-of-your-choice",
#                 'aws_secret_access_key': "secret-key-of-your-choice"},
#             resource_args={
#                 'endpoint_url': 'http://localhost:8000/',
#                 'region_name': 'us-east-1'})
# 
#         manager_dynamo.create_archive_table(
#             table_name,
#             raise_on_err=False)
# 
#         try:
#             yield manager_dynamo
# 
#         finally:
#             manager_dynamo.delete_table(
#                 table_name,
#                 raise_on_err=False)
# 
#     else:
#         raise ValueError('Manager "{}" not recognized'.format(mgr_name))


import pytest
import os
import tempfile
import hashlib
import random
from datafs._compat import u
from tests.resources import prep_manager
from six import b
    with pytest.raises((PermissionError, NameError)):
        with prep_manager('mongo') as manager:
            api.attach_manager(manager)

    with pytest.raises((PermissionError, NameError)):
        api.attach_authority('auth', local_auth)


def test_log_with_various_messages(api):
    '''
    Test :py:meth:`~datafs.core.data_archive.DataArchive.log` stability

    Addresses :issue:`232` - log fails on versions with no message
    '''

    arch = api.create('test/archive1.txt')

    arch.log()

    with arch.open('w+') as f:
        f.write(u('hello 1'))

    arch.log()

    with arch.open('w+', message='hello') as f:
        f.write(u('hello 2'))

    arch.log()

    with arch.open('w+', message=4) as f:

# Path: datafs/_compat.py
# def open_filelike(filelike, mode='r'):
# 
# Path: tests/resources.py
# @contextmanager
# def prep_manager(mgr_name, table_name='my-new-data-table'):
# 
#     if mgr_name == 'mongo':
# 
#         manager_mongo = MongoDBManager(
#             database_name='MyDatabase',
#             table_name=table_name)
# 
#         manager_mongo.create_archive_table(
#             table_name,
#             raise_on_err=False)
# 
#         try:
#             yield manager_mongo
# 
#         finally:
#             manager_mongo.delete_table(
#                 table_name,
#                 raise_on_err=False)
# 
#     elif mgr_name == 'dynamo':
# 
#         manager_dynamo = DynamoDBManager(
#             table_name,
#             session_args={
#                 'aws_access_key_id': "access-key-id-of-your-choice",
#                 'aws_secret_access_key': "secret-key-of-your-choice"},
#             resource_args={
#                 'endpoint_url': 'http://localhost:8000/',
#                 'region_name': 'us-east-1'})
# 
#         manager_dynamo.create_archive_table(
#             table_name,
#             raise_on_err=False)
# 
#         try:
#             yield manager_dynamo
# 
#         finally:
#             manager_dynamo.delete_table(
#                 table_name,
#                 raise_on_err=False)
# 
#     else:
#         raise ValueError('Manager "{}" not recognized'.format(mgr_name))


# Path: tests/test_datafs.py
import pytest
import os
import tempfile
import hashlib
import random
from datafs._compat import u
from tests.resources import prep_manager
from six import b

    with pytest.raises((PermissionError, NameError)):
        with prep_manager('mongo') as manager:
            api.attach_manager(manager)

    with pytest.raises((PermissionError, NameError)):
        api.attach_authority('auth', local_auth)


def test_log_with_various_messages(api):
    '''
    Test :py:meth:`~datafs.core.data_archive.DataArchive.log` stability

    Addresses :issue:`232` - log fails on versions with no message
    '''

    arch = api.create('test/archive1.txt')

    arch.log()

    with arch.open('w+') as f:
        f.write(u('hello 1'))

    arch.log()

    with arch.open('w+', message='hello') as f:
        f.write(u('hello 2'))

    arch.log()

    with arch.open('w+', message=4) as f:

        f.write(u('hello 3'))