# Path: test/base.py
# PY2 = sys.version_info[0] < 3
# ROOT_DIR = abspath(join(dirname(__file__), '..'))
# def to_bytes(s):
# def touch(file_path):
# def build_tmp_pyconcrete(passphrase):
# def copy_pyconcrete_ext(tmp_dir):
# def remove_tmp_pyconcrete():
# def get_pyconcrete_env_path():
#     def __init__(self, *argv, **argd):
#     def setUpClass(cls):
#     def tearDownClass(cls):
#     def setUp(self):
#     def tearDown(self):
#     def lib_gen_py(self, py_code, py_filename, folder=None):
#     def lib_gen_pyc(self, py_code, pyc_filename, folder=None, keep_py=False):
#     def lib_gen_pye(self, py_code, pye_filename, folder=None, keep_py=False, keep_pyc=False):
#     def lib_compile_pyc(self, folder, remove_py=False):
#     def lib_compile_pye(self, folder, remove_py=False, remove_pyc=False):
# class TestPyConcreteBase(unittest.TestCase):
# 
# Path: test/utility.py
# class ImportedTestCase(object):
#     def __init__(self, pyconcrete_exe, module_path):
#         self.pyconcrete_exe = pyconcrete_exe
#         self.module_path = module_path
#         self.tmp_dir = tempfile.mkdtemp(prefix='pyconcrete_testcase_')
# 
#     def close(self):
#         shutil.rmtree(self.tmp_dir)
# 
#     @property
#     def module_name(self):
#         return basename(self.module_path)
# 
#     @property
#     def module_src_path(self):
#         return join(self.module_path, SOURCE_DIR_NAME)
# 
#     def is_available_test_case(self):
#         if not isdir(self.module_path):
#             return False
#         if not self.module_name.startswith(MODULE_PREFIX):
#             return False
# 
#         module_files = os.listdir(self.module_path)
#         if VALIDATOR_PY not in module_files:
#             return False
#         if SOURCE_DIR_NAME not in module_files:
#             return False
# 
#         module_code_files = os.listdir(self.module_src_path)
#         if MAIN_PY not in module_code_files:
#             return False
# 
#         return True
# 
#     def run(self):
#         main_pye_path = self.build_pye()
#         ret_data = self.execute(main_pye_path)
#         return self.validate(ret_data, main_pye_path)
# 
#     def build_pye(self):
#         dest_dir = join(self.tmp_dir, self.module_name)
#         shutil.copytree(self.module_src_path, dest_dir)
# 
#         lib_compile_pye(dest_dir, remove_py=True, remove_pyc=True)
#         return join(dest_dir, 'main.pye')
# 
#     def execute(self, main_pye_path):
#         p = subprocess.Popen(
#             [self.pyconcrete_exe, main_pye_path],
#             stdin=subprocess.DEVNULL,
#             stdout=subprocess.PIPE,
#             stderr=subprocess.STDOUT,
#         )
#         output, error = p.communicate()
#         output = output.decode('utf8')
#         output = output.replace('\r\n', '\n')
#         return {
#             'output_lines': output.strip().split('\n'),
#             'return_code': p.returncode,
#         }
# 
#     def validate(self, ret_data, main_pye_path):
#         validator_py = join(self.module_path, VALIDATOR_PY)
#         validator = imp.load_source('', validator_py)
#         try:
#             return validator.validate(
#                 ret_data['output_lines'],
#                 main_pye_path=main_pye_path,
#                 return_code=ret_data['return_code'],
#             )
#         except Exception as e:
#             raise ImportedTestCaseError(ret_data['output_lines'], ret_data['return_code'], str(e))
# 
# class ImportedTestCaseError(Exception):
#     def __init__(self, output_lines, return_code, validate_errors, *args, **kwargs):
#         self.output_lines = output_lines
#         self.return_code = return_code
#         self.validate_errors = validate_errors


import os
from os.path import join
from test import base
from test.utility import ImportedTestCase, ImportedTestCaseError
#!/usr/bin/env python
# -*- coding: utf8 -*-
# Create on : 2019/07/13
from __future__ import unicode_literals



class TestExe(base.TestPyConcreteBase):
    def discover(self):
        test_cases = []
        test_case_dir = join(base.ROOT_DIR, 'test', 'exe_testcases')
        for d in os.listdir(test_case_dir):
            test_case_path = join(test_case_dir, d)

# Path: test/base.py
# PY2 = sys.version_info[0] < 3
# ROOT_DIR = abspath(join(dirname(__file__), '..'))
# def to_bytes(s):
# def touch(file_path):
# def build_tmp_pyconcrete(passphrase):
# def copy_pyconcrete_ext(tmp_dir):
# def remove_tmp_pyconcrete():
# def get_pyconcrete_env_path():
#     def __init__(self, *argv, **argd):
#     def setUpClass(cls):
#     def tearDownClass(cls):
#     def setUp(self):
#     def tearDown(self):
#     def lib_gen_py(self, py_code, py_filename, folder=None):
#     def lib_gen_pyc(self, py_code, pyc_filename, folder=None, keep_py=False):
#     def lib_gen_pye(self, py_code, pye_filename, folder=None, keep_py=False, keep_pyc=False):
#     def lib_compile_pyc(self, folder, remove_py=False):
#     def lib_compile_pye(self, folder, remove_py=False, remove_pyc=False):
# class TestPyConcreteBase(unittest.TestCase):
# 
# Path: test/utility.py
# class ImportedTestCase(object):
#     def __init__(self, pyconcrete_exe, module_path):
#         self.pyconcrete_exe = pyconcrete_exe
#         self.module_path = module_path
#         self.tmp_dir = tempfile.mkdtemp(prefix='pyconcrete_testcase_')
# 
#     def close(self):
#         shutil.rmtree(self.tmp_dir)
# 
#     @property
#     def module_name(self):
#         return basename(self.module_path)
# 
#     @property
#     def module_src_path(self):
#         return join(self.module_path, SOURCE_DIR_NAME)
# 
#     def is_available_test_case(self):
#         if not isdir(self.module_path):
#             return False
#         if not self.module_name.startswith(MODULE_PREFIX):
#             return False
# 
#         module_files = os.listdir(self.module_path)
#         if VALIDATOR_PY not in module_files:
#             return False
#         if SOURCE_DIR_NAME not in module_files:
#             return False
# 
#         module_code_files = os.listdir(self.module_src_path)
#         if MAIN_PY not in module_code_files:
#             return False
# 
#         return True
# 
#     def run(self):
#         main_pye_path = self.build_pye()
#         ret_data = self.execute(main_pye_path)
#         return self.validate(ret_data, main_pye_path)
# 
#     def build_pye(self):
#         dest_dir = join(self.tmp_dir, self.module_name)
#         shutil.copytree(self.module_src_path, dest_dir)
# 
#         lib_compile_pye(dest_dir, remove_py=True, remove_pyc=True)
#         return join(dest_dir, 'main.pye')
# 
#     def execute(self, main_pye_path):
#         p = subprocess.Popen(
#             [self.pyconcrete_exe, main_pye_path],
#             stdin=subprocess.DEVNULL,
#             stdout=subprocess.PIPE,
#             stderr=subprocess.STDOUT,
#         )
#         output, error = p.communicate()
#         output = output.decode('utf8')
#         output = output.replace('\r\n', '\n')
#         return {
#             'output_lines': output.strip().split('\n'),
#             'return_code': p.returncode,
#         }
# 
#     def validate(self, ret_data, main_pye_path):
#         validator_py = join(self.module_path, VALIDATOR_PY)
#         validator = imp.load_source('', validator_py)
#         try:
#             return validator.validate(
#                 ret_data['output_lines'],
#                 main_pye_path=main_pye_path,
#                 return_code=ret_data['return_code'],
#             )
#         except Exception as e:
#             raise ImportedTestCaseError(ret_data['output_lines'], ret_data['return_code'], str(e))
# 
# class ImportedTestCaseError(Exception):
#     def __init__(self, output_lines, return_code, validate_errors, *args, **kwargs):
#         self.output_lines = output_lines
#         self.return_code = return_code
#         self.validate_errors = validate_errors


# Path: test/test_exe_testcases.py
import os
from os.path import join
from test import base
from test.utility import ImportedTestCase, ImportedTestCaseError

#!/usr/bin/env python
# -*- coding: utf8 -*-
# Create on : 2019/07/13
from __future__ import unicode_literals



class TestExe(base.TestPyConcreteBase):
    def discover(self):
        test_cases = []
        test_case_dir = join(base.ROOT_DIR, 'test', 'exe_testcases')
        for d in os.listdir(test_case_dir):
            test_case_path = join(test_case_dir, d)

            itc = ImportedTestCase(self._pyconcrete_exe, test_case_path)