# Path: elbepack/directories.py
# def init_directories(elbe_relpath):
# def get_cmdlist():
# 
# Path: elbepack/commands/test.py
# class ElbeTestCase(unittest.TestCase):
# 
#     level = ElbeTestLevel.BASE
# 
#     def __init__(self, methodName='runTest', param=None):
#         self.methodName = methodName
#         self.param = param
#         self.stdout = None
#         super().__init__(methodName)
# 
#     def __str__(self):
#         name = super(ElbeTestCase, self).__str__()
#         if self.param:
#             return "%s : param=%s" % (name, self.param)
#         return name
# 
#     def parameterize(self, param):
#         return self.__class__(methodName=self.methodName, param=param)
# 
# class ElbeTestLevel(enum.IntEnum):
#     BASE   = enum.auto()
#     EXTEND = enum.auto()
#     INITVM = enum.auto()
#     FULL   = enum.auto()
# 
# def system(cmd, allow_fail=False):
#     ret, out = command_out(cmd)
#     if ret != 0 and not allow_fail:
#         raise ElbeTestException(cmd, ret, out)


import os
import unittest
import tempfile
from elbepack.directories import elbe_dir, elbe_exe
from elbepack.commands.test import ElbeTestCase, ElbeTestLevel, system
                 "Test level not set to INITVM")
class TestPbuilder(ElbeTestCase):

    params = [os.path.join(elbe_dir, "tests", fname)
              for fname
              in os.listdir(os.path.join(elbe_dir, "tests"))
              if fname.startswith("pbuilder") and fname.endswith(".xml")]

    def test_pbuilder_build(self):

        with tempfile.TemporaryDirectory(prefix="elbe-test-pbuilder-xml-") as build_dir:

            prj  = os.path.join(build_dir, "uuid.prj")
            uuid = None

            try:
                system(f'{elbe_exe} pbuilder create --xmlfile "{self.param}" \
                                                    --writeproject "{prj}"')
                system(f'cd "{build_dir}"; \
                         git clone https://github.com/Linutronix/libgpio.git')

                with open(prj, "r") as f:
                    uuid = f.read()
                    system(f'cd "{build_dir}/libgpio"; \
                             {elbe_exe} pbuilder build --project {uuid}')
            # pylint: disable=try-except-raise
            except:
                raise
            else:
                # This is a tearDown of the project, it's okay if it fails

# Path: elbepack/directories.py
# def init_directories(elbe_relpath):
# def get_cmdlist():
# 
# Path: elbepack/commands/test.py
# class ElbeTestCase(unittest.TestCase):
# 
#     level = ElbeTestLevel.BASE
# 
#     def __init__(self, methodName='runTest', param=None):
#         self.methodName = methodName
#         self.param = param
#         self.stdout = None
#         super().__init__(methodName)
# 
#     def __str__(self):
#         name = super(ElbeTestCase, self).__str__()
#         if self.param:
#             return "%s : param=%s" % (name, self.param)
#         return name
# 
#     def parameterize(self, param):
#         return self.__class__(methodName=self.methodName, param=param)
# 
# class ElbeTestLevel(enum.IntEnum):
#     BASE   = enum.auto()
#     EXTEND = enum.auto()
#     INITVM = enum.auto()
#     FULL   = enum.auto()
# 
# def system(cmd, allow_fail=False):
#     ret, out = command_out(cmd)
#     if ret != 0 and not allow_fail:
#         raise ElbeTestException(cmd, ret, out)


# Path: elbepack/tests/test_xml.py
import os
import unittest
import tempfile
from elbepack.directories import elbe_dir, elbe_exe
from elbepack.commands.test import ElbeTestCase, ElbeTestLevel, system

                 "Test level not set to INITVM")
class TestPbuilder(ElbeTestCase):

    params = [os.path.join(elbe_dir, "tests", fname)
              for fname
              in os.listdir(os.path.join(elbe_dir, "tests"))
              if fname.startswith("pbuilder") and fname.endswith(".xml")]

    def test_pbuilder_build(self):

        with tempfile.TemporaryDirectory(prefix="elbe-test-pbuilder-xml-") as build_dir:

            prj  = os.path.join(build_dir, "uuid.prj")
            uuid = None

            try:
                system(f'{elbe_exe} pbuilder create --xmlfile "{self.param}" \
                                                    --writeproject "{prj}"')
                system(f'cd "{build_dir}"; \
                         git clone https://github.com/Linutronix/libgpio.git')

                with open(prj, "r") as f:
                    uuid = f.read()
                    system(f'cd "{build_dir}/libgpio"; \
                             {elbe_exe} pbuilder build --project {uuid}')
            # pylint: disable=try-except-raise
            except:
                raise
            else:
                # This is a tearDown of the project, it's okay if it fails

                system('%s control del_project %s' % (elbe_exe, uuid),