# Path: invtool/main.py
# def do_dispatch(args, IN=sys.stdin):
# def main(args):
# 
# Path: invtool/tests/utils.py
# def call_to_json(command_str):
#     """
#     Given a string, this function will shell out, execute the command
#     and parse the json returned by that command
#     """
#     print command_str
#     p = subprocess.Popen(shlex.split(command_str),
#                          stderr=subprocess.PIPE, stdout=subprocess.PIPE)
#     stdout, stderr = p.communicate()
#     if stderr:
#         return None, stderr, p.returncode
# 
#     stdout = stdout.replace('u\'', '"').replace('\'', '"').strip('\n')
#     try:
#         return json.loads(stdout, 'unicode'), None, p.returncode
#     except json.decoder.JSONDecodeError, e:
#         return (None,
#                 "Ret was: {0}. Got error: {1}".format(stdout, str(e)),
#                 p.returncode)
# 
# def test_method_to_params(test_case):
#     if not test_case:
#         return ''
#     elif not test_case[0]:
#         return test_case[1]
#     else:
#         return "--{0} {1}".format(*test_case)
# 
# EXEC = "./inv --json"


import unittest
import sys
from gettext import gettext as _
from invtool.main import registrar
from invtool.tests.utils import call_to_json, test_method_to_params, EXEC


sys.path.insert(0, '')

__import__('invtool.main')


def run_tests():
    def build_testcase(dispatch, commands):
        """
        The first command is used to create an object. Using the pk returned
        from the object's creation we look up the object and use the second
        command to update the object. The object is then deleted and finally
        the object is looked up again to ensure a 404.
        """
        class _TestCase(unittest.TestCase):
            pass

        def place_holder(self):
            # This should create an object that we can use to associate KV's to
            print "testing {0} ...".format(dispatch.dtype)
            obj_pk = dispatch.do_test_setup(self)

            # List the object's KV store and remember the count
            def list_kv():
                list_command = _("{0} {1} list --obj-pk {2}".format(
                    EXEC, dispatch.dtype, obj_pk)
                )

# Path: invtool/main.py
# def do_dispatch(args, IN=sys.stdin):
# def main(args):
# 
# Path: invtool/tests/utils.py
# def call_to_json(command_str):
#     """
#     Given a string, this function will shell out, execute the command
#     and parse the json returned by that command
#     """
#     print command_str
#     p = subprocess.Popen(shlex.split(command_str),
#                          stderr=subprocess.PIPE, stdout=subprocess.PIPE)
#     stdout, stderr = p.communicate()
#     if stderr:
#         return None, stderr, p.returncode
# 
#     stdout = stdout.replace('u\'', '"').replace('\'', '"').strip('\n')
#     try:
#         return json.loads(stdout, 'unicode'), None, p.returncode
#     except json.decoder.JSONDecodeError, e:
#         return (None,
#                 "Ret was: {0}. Got error: {1}".format(stdout, str(e)),
#                 p.returncode)
# 
# def test_method_to_params(test_case):
#     if not test_case:
#         return ''
#     elif not test_case[0]:
#         return test_case[1]
#     else:
#         return "--{0} {1}".format(*test_case)
# 
# EXEC = "./inv --json"


# Path: invtool/tests/kv_tests.py
import unittest
import sys
from gettext import gettext as _
from invtool.main import registrar
from invtool.tests.utils import call_to_json, test_method_to_params, EXEC



sys.path.insert(0, '')

__import__('invtool.main')


def run_tests():
    def build_testcase(dispatch, commands):
        """
        The first command is used to create an object. Using the pk returned
        from the object's creation we look up the object and use the second
        command to update the object. The object is then deleted and finally
        the object is looked up again to ensure a 404.
        """
        class _TestCase(unittest.TestCase):
            pass

        def place_holder(self):
            # This should create an object that we can use to associate KV's to
            print "testing {0} ...".format(dispatch.dtype)
            obj_pk = dispatch.do_test_setup(self)

            # List the object's KV store and remember the count
            def list_kv():
                list_command = _("{0} {1} list --obj-pk {2}".format(
                    EXEC, dispatch.dtype, obj_pk)
                )

                ret, errors, rc = call_to_json(list_command)