Exemple #1
0
    def test_05(self):
        """
        Test Case 05:
        Open a file using :py:func:`magrathea.utils.compat.comp_open`.

        Test is passed if file content can be read and equals the given input.
        """
        test_string = "String with Ünicøde characters"
        fp, name = tempfile.mkstemp()
        os.write(fp, to_bytes(test_string))
        os.close(fp)
        fd = comp_open(name, mode='r', encoding=get_conf('DEFAULT_CHARSET'))
        result_string = fd.read()
        fd.close()
        os.unlink(name)
        self.assertEqual(test_string, result_string)
Exemple #2
0
    def test_06(self):
        """
        Test Case 06:
        Use :py:func:`magrathea.utils.compat.comp_open` as :py:keyword:`with` statement context manager.

        Test is passed if file content can be read, equals the given input and the file pointer is closed.
        """
        test_string = "String with Ünicøde characters"
        fp, name = tempfile.mkstemp()
        os.write(fp, to_bytes(test_string))
        os.close(fp)
        with comp_open(name, mode='r', encoding=get_conf('DEFAULT_CHARSET')) as fd:
            result_string = fd.read()
        os.unlink(name)
        self.assertTrue(fd.closed)
        self.assertEqual(test_string, result_string)
Exemple #3
0
    def test_07(self):
        """
        Test Case 07:
        Deploy a template into a temporary directory.

        Test is passed if deployment doesn't raise exception and all expected files exist.
        """
        def _filter(item):
            _file_map = {
                'makefile': 'Makefile',
                'cmakelists.txt': 'CMakeLists.txt',
                'readme': 'README'
            }
            if item in _file_map:
                return _file_map[item]
            return item

        td = tempfile.mkdtemp()
        obj = Template(template='planet', path=td)
        obj.deploy()
        cp = CompConfigParser(allow_no_value=True)
        cf = ApplicationConf.get_instance()
        with comp_open(os.path.join(get_conf('DEFAULT_TEMPLATE_PATH'), 'planet', '__init__.ini'), mode='r') as fp:
            content = fp.read()
            content = content.format(**cf)
        cp.read_string(content)
        flag = True
        if cp.has_section('dirs'):
            for directory in cp.options('dirs'):
                flag = flag and os.path.exists(os.path.join(obj.path, directory))
        if cp.has_section('files'):
            for file in cp.options('files'):
                flag = flag and os.path.exists(os.path.join(obj.path, _filter(file)))
        if cp.has_section('binaries'):
            for binary in cp.options('binaries'):
                flag = flag and os.path.exists(os.path.join(obj.path, _filter(binary)))
        shutil.rmtree(td)
        self.assertTrue(flag)