# Path: rash/utils/py3compat.py
# PY3 = (sys.version_info[0] >= 3)
# 
# Path: rash/config.py
# class ConfigStore(object):
# 
#     """
#     Configuration and data file store.
# 
#     RASH stores data in the following directory in Linux::
# 
#       * ~/.config/               # $XDG_CONFIG_HOME
#       `--* rash/                 # base_path
#          |--* daemon.pid         # PID of daemon process
#          |--* daemon.log         # Log file for daemon
#          `--* data/              # data_path
#             |--* db.sqlite       # db_path ("indexed" record)
#             `--* record/         # record_path ("raw" record)
#                |--* command/     # command log
#                `--* init/        # initialization log
# 
#     In Mac OS and Windows, :attr:`base_path` may be different but
#     structure in the directory is the same.
# 
#     """
# 
#     def __init__(self, base_path=None):
#         self.base_path = base_path or get_config_directory('RASH')
#         """
#         Root directory for any RASH related data files (``~/.config/rash``).
#         """
# 
#         self.config_path = os.path.join(self.base_path, 'config.py')
#         """
#         File to store user configuration (``~/.config/rash/config.py``).
#         """
# 
#         self.data_path = os.path.join(self.base_path, 'data')
#         """
#         Directory to store data collected by RASH (``~/.config/rash/data``).
#         """
# 
#         self.record_path = os.path.join(self.data_path, 'record')
#         """
#         Shell history is stored in this directory at the first stage.
#         """
# 
#         self.db_path = os.path.join(self.data_path, 'db.sqlite')
#         """
#         Shell history is stored in the DB at this path.
#         """
# 
#         self.daemon_pid_path = os.path.join(self.base_path, 'daemon.pid')
#         """
#         A file to store daemon PID (``~/.config/rash/daemon.pid``).
#         """
# 
#         self.daemon_log_path = os.path.join(self.base_path, 'daemon.log')
#         """
#         Daemon log file (``~/.config/rash/daemon.log``).
#         """
# 
#         self.daemon_log_level = 'INFO'  # FIXME: make this configurable
#         """
#         Daemon log level.
#         """
# 
#         mkdirp(self.record_path)
# 
#     def get_config(self):
#         """
#         Load user configuration or return default when not found.
# 
#         :rtype: :class:`Configuration`
# 
#         """
#         if not self._config:
#             namespace = {}
#             if os.path.exists(self.config_path):
#                 execfile(self.config_path, namespace)
#             self._config = namespace.get('config') or Configuration()
#         return self._config
#     _config = None
# 
# Path: rash/tests/utils.py
# class BaseTestCase(unittest.TestCase):
# 
#     if not hasattr(unittest.TestCase, 'assertIn'):
#         def assertIn(self, member, container):
#             self.assertTrue(member in container)
# 
#     if not hasattr(unittest.TestCase, 'assertNotIn'):
#         def assertNotIn(self, member, container):
#             self.assertTrue(member not in container)
# 
#     if not hasattr(unittest.TestCase, 'assertIsInstance'):
#         def assertIsInstance(self, obj, cls, msg=None):
#             self.assertTrue(isinstance(obj, cls), msg)
# 
#     if not hasattr(unittest.TestCase, 'assertSetEqual'):
#         def assertSetEqual(self, set1, set2, msg=None):
#             self.assertEqual(set1, set2, msg)
# 
# def skipIf(condition, reason):
#     def decorator(func):
#         @functools.wraps(func)
#         def wrapper(*args, **kwds):
#             if condition:
#                 print("Skipping {0} because:".format(func.__name__))
#                 print(reason)
#             else:
#                 return func(*args, **kwds)
#         return wrapper
#     return decorator


import os
import sys
import subprocess
import unittest
import tempfile
import shutil
import textwrap
import json
import time
from ..utils.py3compat import PY3
from ..config import ConfigStore
from ..tests.utils import BaseTestCase, skipIf
        from ..record import get_environ
            raise RuntimeError('Do not use env!')
        if 'cwd' in kwds:
            raise RuntimeError('Do not use cwd!')
        kwds['env'] = self.environ
        kwds['cwd'] = self.home_dir
        return subprocess.Popen(*args, **kwds)


class TestIsolation(FunctionalTestMixIn, BaseTestCase):

    """
    Make sure that test environment is isolated from the real one.
    """

    def test_config_isolation(self):
        proc = self.popen(
            [os.path.abspath(sys.executable)],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate(textwrap.dedent("""
        from rash.config import ConfigStore
        cfstore = ConfigStore()
        print(repr(cfstore.base_path))
        """).encode())
        stderr = stderr.decode()
        stdout = stdout.decode()
        base_path = eval(stdout)
        self.assertEqual(base_path, self.conf_base_path)
        self.assertFalse(stderr)

# Path: rash/utils/py3compat.py
# PY3 = (sys.version_info[0] >= 3)
# 
# Path: rash/config.py
# class ConfigStore(object):
# 
#     """
#     Configuration and data file store.
# 
#     RASH stores data in the following directory in Linux::
# 
#       * ~/.config/               # $XDG_CONFIG_HOME
#       `--* rash/                 # base_path
#          |--* daemon.pid         # PID of daemon process
#          |--* daemon.log         # Log file for daemon
#          `--* data/              # data_path
#             |--* db.sqlite       # db_path ("indexed" record)
#             `--* record/         # record_path ("raw" record)
#                |--* command/     # command log
#                `--* init/        # initialization log
# 
#     In Mac OS and Windows, :attr:`base_path` may be different but
#     structure in the directory is the same.
# 
#     """
# 
#     def __init__(self, base_path=None):
#         self.base_path = base_path or get_config_directory('RASH')
#         """
#         Root directory for any RASH related data files (``~/.config/rash``).
#         """
# 
#         self.config_path = os.path.join(self.base_path, 'config.py')
#         """
#         File to store user configuration (``~/.config/rash/config.py``).
#         """
# 
#         self.data_path = os.path.join(self.base_path, 'data')
#         """
#         Directory to store data collected by RASH (``~/.config/rash/data``).
#         """
# 
#         self.record_path = os.path.join(self.data_path, 'record')
#         """
#         Shell history is stored in this directory at the first stage.
#         """
# 
#         self.db_path = os.path.join(self.data_path, 'db.sqlite')
#         """
#         Shell history is stored in the DB at this path.
#         """
# 
#         self.daemon_pid_path = os.path.join(self.base_path, 'daemon.pid')
#         """
#         A file to store daemon PID (``~/.config/rash/daemon.pid``).
#         """
# 
#         self.daemon_log_path = os.path.join(self.base_path, 'daemon.log')
#         """
#         Daemon log file (``~/.config/rash/daemon.log``).
#         """
# 
#         self.daemon_log_level = 'INFO'  # FIXME: make this configurable
#         """
#         Daemon log level.
#         """
# 
#         mkdirp(self.record_path)
# 
#     def get_config(self):
#         """
#         Load user configuration or return default when not found.
# 
#         :rtype: :class:`Configuration`
# 
#         """
#         if not self._config:
#             namespace = {}
#             if os.path.exists(self.config_path):
#                 execfile(self.config_path, namespace)
#             self._config = namespace.get('config') or Configuration()
#         return self._config
#     _config = None
# 
# Path: rash/tests/utils.py
# class BaseTestCase(unittest.TestCase):
# 
#     if not hasattr(unittest.TestCase, 'assertIn'):
#         def assertIn(self, member, container):
#             self.assertTrue(member in container)
# 
#     if not hasattr(unittest.TestCase, 'assertNotIn'):
#         def assertNotIn(self, member, container):
#             self.assertTrue(member not in container)
# 
#     if not hasattr(unittest.TestCase, 'assertIsInstance'):
#         def assertIsInstance(self, obj, cls, msg=None):
#             self.assertTrue(isinstance(obj, cls), msg)
# 
#     if not hasattr(unittest.TestCase, 'assertSetEqual'):
#         def assertSetEqual(self, set1, set2, msg=None):
#             self.assertEqual(set1, set2, msg)
# 
# def skipIf(condition, reason):
#     def decorator(func):
#         @functools.wraps(func)
#         def wrapper(*args, **kwds):
#             if condition:
#                 print("Skipping {0} because:".format(func.__name__))
#                 print(reason)
#             else:
#                 return func(*args, **kwds)
#         return wrapper
#     return decorator


# Path: rash/functional_tests/test_cli.py
import os
import sys
import subprocess
import unittest
import tempfile
import shutil
import textwrap
import json
import time
from ..utils.py3compat import PY3
from ..config import ConfigStore
from ..tests.utils import BaseTestCase, skipIf
        from ..record import get_environ

            raise RuntimeError('Do not use env!')
        if 'cwd' in kwds:
            raise RuntimeError('Do not use cwd!')
        kwds['env'] = self.environ
        kwds['cwd'] = self.home_dir
        return subprocess.Popen(*args, **kwds)


class TestIsolation(FunctionalTestMixIn, BaseTestCase):

    """
    Make sure that test environment is isolated from the real one.
    """

    def test_config_isolation(self):
        proc = self.popen(
            [os.path.abspath(sys.executable)],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        (stdout, stderr) = proc.communicate(textwrap.dedent("""
        from rash.config import ConfigStore
        cfstore = ConfigStore()
        print(repr(cfstore.base_path))
        """).encode())
        stderr = stderr.decode()
        stdout = stdout.decode()
        base_path = eval(stdout)
        self.assertEqual(base_path, self.conf_base_path)
        self.assertFalse(stderr)

        self.assertNotEqual(base_path, ConfigStore().base_path)