# Path: taxtastic/scripts/taxit.py
# def main(argv=None):
#     argv = argv or sys.argv[1:]
#     action, arguments = parse_arguments(argv)
# 
#     loglevel = {
#         0: logging.ERROR,
#         1: logging.WARNING,
#         2: logging.INFO,
#         3: logging.DEBUG,
#     }.get(arguments.verbosity, logging.DEBUG)
# 
#     if arguments.verbosity > 1:
#         logformat = '%(levelname)s %(module)s %(lineno)s %(message)s'
#     else:
#         logformat = '%(message)s'
# 
#     # set up logging
#     logging.basicConfig(stream=sys.stderr, format=logformat, level=loglevel)
# 
#     try:
#         return action(arguments)
#     finally:
#         subcommands.close_all_files(arguments)
# 
# Path: taxtastic/refpkg.py
# FORMAT_VERSION = '1.1'
# class DerivedFileNotUpdatedWarning(UserWarning):
# class NoAncestor(Exception):
# class Refpkg(object):
# def is_string(val):
# def md5file(fobj):
# def scratch_file(unlink=True, **kwargs):
# def manifest_template():
# def transaction(f, self, *args, **kwargs):
#     def __init__(self, path, create=None):
#     def _install_zipfile_handlers(self):
#         def zipopen(name, *mode):
#         def file_path(name):
#     def file_path(self, name):
#     def open(self, name, *mode):
#     def open_manifest(self, *mode):
#     def open_resource(self, resource, *mode):
#     def resource_name(self, resource):
#     def resource_md5(self, resource):
#     def calculate_resource_md5(self, resource):
#     def resource_path(self, resource):
#     def _set_defaults(self):
#     def _sync_to_disk(self):
#     def _sync_from_disk(self):
#     def _add_file(self, key, path):
#     def _delete_file(self, path):
#     def metadata(self, key):
#     def file_keys(self):
#     def metadata_keys(self):
#     def _log(self, msg):
#     def log(self):
#     def is_invalid(self):
#     def _check_refpkg(self):
#     def update_metadata(self, key, value):
#     def update_file(self, key, new_path):
#     def reroot(self, rppr=None, pretend=False):
#     def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
#     def rollback(self):
#     def rollforward(self):
#     def strip(self):
#     def start_transaction(self):
#     def commit_transaction(self, log=None):
#     def is_ill_formed(self):
#     def load_db(self):
#     def most_recent_common_ancestor(self, *ts):
#     def _large_mrca(self, ts):
#     def _small_mrca(self, ts):
#     def file_abspath(self, resource):
#     def file_name(self, resource):
#     def file_md5(self, resource):
# 
# Path: tests/config.py
# class TestScriptBase(OutputRedirectMixin, TestBase):
# 
#     """
#     Base class for unit tests of scripts distributed with this
#     package. Create a new test module like this::
# 
#       from config import TestScriptBase
#       TestScriptBase.executable = './script_name.py'
#       TestScriptBase.outputdir = 'path/to/somewhere'
# 
#       class TestSomething(TestScriptBase):
# 
#           def test01(self):
#               self.cmd_ok('--help')
# 
#     """
# 
#     executable = None
#     openargs = {'mode': 'rU'} if sys.version_info.major == 2 else {'newline': None}
# 
#     def __getitem__(self, i):
#         """
#         Enables string formatting, eg:
#         print 'current function: %(funcname)s' % self
#         """
#         return getattr(self, i)
# 
#     def wrap_cmd(self, cmd):
#         cmd = cmd % self
#         try:
#             retval = main(cmd.split())
#         except SystemExit as err:
#             return None, err
#         else:
#             return retval, None
# 
#     def cmd_ok(self, cmd):
#         retval, err = self.wrap_cmd(cmd)
#         if err:
#             self.assertEqual(errval(err), 0)
#         else:
#             self.assertFalse(bool(retval))
# 
#     def cmd_fails(self, cmd):
#         retval, err = self.wrap_cmd(cmd)
#         if err:
#             self.assertNotEqual(errval(err), 0)
#         else:
#             self.assertTrue(bool(retval))
# 
# class TestBase(unittest.TestCase):
#     """
#     Base class for unit tests
#     """
# 
#     outputdir = outputdir
# 
#     def outdir(self):
#         """
#         Name an outputdir as outpudir/module.class.method
#         """
#         funcname = '.'.join(self.id().split('.')[-3:])
#         return path.join(self.outputdir, funcname)
# 
#     def mkoutdir(self, clobber=True):
#         """
#         Create output directory (destructively if clobber is True)
#         """
# 
#         outdir = self.outdir()
#         mkdir(outdir, clobber)
#         return outdir
# 
#     def suppress_stdout(self):
#         self.old_stdout = sys.stdout
#         sys.stdout = StringIO()
# 
#     def suppress_stderr(self):
#         self.old_stderr = sys.stderr
#         sys.stderr = StringIO()
# 
#     def tearDown(self):
#         if hasattr(self, 'old_stdout'):
#             sys.stdout = self.old_stdout
#         if hasattr(self, 'old_stderr'):
#             sys.stdout = self.old_stderr


import json
import logging
import shutil
import sys
from os import path
from taxtastic.scripts.taxit import main
from taxtastic import refpkg
from . import config
from .config import TestScriptBase, TestBase



log = logging

TestScriptBase.executable = path.join(path.dirname(__file__), '..', 'taxit.py')
TestScriptBase.outputdir = config.outputdir

# Path: taxtastic/scripts/taxit.py
# def main(argv=None):
#     argv = argv or sys.argv[1:]
#     action, arguments = parse_arguments(argv)
# 
#     loglevel = {
#         0: logging.ERROR,
#         1: logging.WARNING,
#         2: logging.INFO,
#         3: logging.DEBUG,
#     }.get(arguments.verbosity, logging.DEBUG)
# 
#     if arguments.verbosity > 1:
#         logformat = '%(levelname)s %(module)s %(lineno)s %(message)s'
#     else:
#         logformat = '%(message)s'
# 
#     # set up logging
#     logging.basicConfig(stream=sys.stderr, format=logformat, level=loglevel)
# 
#     try:
#         return action(arguments)
#     finally:
#         subcommands.close_all_files(arguments)
# 
# Path: taxtastic/refpkg.py
# FORMAT_VERSION = '1.1'
# class DerivedFileNotUpdatedWarning(UserWarning):
# class NoAncestor(Exception):
# class Refpkg(object):
# def is_string(val):
# def md5file(fobj):
# def scratch_file(unlink=True, **kwargs):
# def manifest_template():
# def transaction(f, self, *args, **kwargs):
#     def __init__(self, path, create=None):
#     def _install_zipfile_handlers(self):
#         def zipopen(name, *mode):
#         def file_path(name):
#     def file_path(self, name):
#     def open(self, name, *mode):
#     def open_manifest(self, *mode):
#     def open_resource(self, resource, *mode):
#     def resource_name(self, resource):
#     def resource_md5(self, resource):
#     def calculate_resource_md5(self, resource):
#     def resource_path(self, resource):
#     def _set_defaults(self):
#     def _sync_to_disk(self):
#     def _sync_from_disk(self):
#     def _add_file(self, key, path):
#     def _delete_file(self, path):
#     def metadata(self, key):
#     def file_keys(self):
#     def metadata_keys(self):
#     def _log(self, msg):
#     def log(self):
#     def is_invalid(self):
#     def _check_refpkg(self):
#     def update_metadata(self, key, value):
#     def update_file(self, key, new_path):
#     def reroot(self, rppr=None, pretend=False):
#     def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
#     def rollback(self):
#     def rollforward(self):
#     def strip(self):
#     def start_transaction(self):
#     def commit_transaction(self, log=None):
#     def is_ill_formed(self):
#     def load_db(self):
#     def most_recent_common_ancestor(self, *ts):
#     def _large_mrca(self, ts):
#     def _small_mrca(self, ts):
#     def file_abspath(self, resource):
#     def file_name(self, resource):
#     def file_md5(self, resource):
# 
# Path: tests/config.py
# class TestScriptBase(OutputRedirectMixin, TestBase):
# 
#     """
#     Base class for unit tests of scripts distributed with this
#     package. Create a new test module like this::
# 
#       from config import TestScriptBase
#       TestScriptBase.executable = './script_name.py'
#       TestScriptBase.outputdir = 'path/to/somewhere'
# 
#       class TestSomething(TestScriptBase):
# 
#           def test01(self):
#               self.cmd_ok('--help')
# 
#     """
# 
#     executable = None
#     openargs = {'mode': 'rU'} if sys.version_info.major == 2 else {'newline': None}
# 
#     def __getitem__(self, i):
#         """
#         Enables string formatting, eg:
#         print 'current function: %(funcname)s' % self
#         """
#         return getattr(self, i)
# 
#     def wrap_cmd(self, cmd):
#         cmd = cmd % self
#         try:
#             retval = main(cmd.split())
#         except SystemExit as err:
#             return None, err
#         else:
#             return retval, None
# 
#     def cmd_ok(self, cmd):
#         retval, err = self.wrap_cmd(cmd)
#         if err:
#             self.assertEqual(errval(err), 0)
#         else:
#             self.assertFalse(bool(retval))
# 
#     def cmd_fails(self, cmd):
#         retval, err = self.wrap_cmd(cmd)
#         if err:
#             self.assertNotEqual(errval(err), 0)
#         else:
#             self.assertTrue(bool(retval))
# 
# class TestBase(unittest.TestCase):
#     """
#     Base class for unit tests
#     """
# 
#     outputdir = outputdir
# 
#     def outdir(self):
#         """
#         Name an outputdir as outpudir/module.class.method
#         """
#         funcname = '.'.join(self.id().split('.')[-3:])
#         return path.join(self.outputdir, funcname)
# 
#     def mkoutdir(self, clobber=True):
#         """
#         Create output directory (destructively if clobber is True)
#         """
# 
#         outdir = self.outdir()
#         mkdir(outdir, clobber)
#         return outdir
# 
#     def suppress_stdout(self):
#         self.old_stdout = sys.stdout
#         sys.stdout = StringIO()
# 
#     def suppress_stderr(self):
#         self.old_stderr = sys.stderr
#         sys.stderr = StringIO()
# 
#     def tearDown(self):
#         if hasattr(self, 'old_stdout'):
#             sys.stdout = self.old_stdout
#         if hasattr(self, 'old_stderr'):
#             sys.stdout = self.old_stderr


# Path: tests/test_taxit.py
import json
import logging
import shutil
import sys
from os import path
from taxtastic.scripts.taxit import main
from taxtastic import refpkg
from . import config
from .config import TestScriptBase, TestBase




log = logging

TestScriptBase.executable = path.join(path.dirname(__file__), '..', 'taxit.py')
TestScriptBase.outputdir = config.outputdir

TestScriptBase.taxdb = 'sqlite:///' + config.ncbi_master_db