コード例 #1
0
ファイル: tests.py プロジェクト: iffanux/vstutils
    def test_render_and_file(self):
        err_ini = utils.get_render('configs/config.ini',
                                   dict(config=dict(test=[])))
        for line in err_ini.split('\n'):
            self.assertEqual(line[0], '#')
        self.assertTrue('# Invalid config.' in err_ini, err_ini)
        config_dict = dict(config=dict(main=dict(test_key="test_value")))
        ini = utils.get_render('configs/config.ini', config_dict)
        with utils.tmp_file_context(ini, delete=False) as file:
            file_name = file.name
            file.write('\n')
            with open(file_name, 'r') as tmp_file:
                self.assertEqual(tmp_file.read(), test_config)
        try:
            self.assertFalse(utils.os.path.exists(file_name))
        except AssertionError:  # nocv
            utils.os.remove(file_name)
        try:
            with utils.tmp_file(ini) as file:
                file_name = file.name
                file.write('\n')
                with open(file_name, 'r') as tmp_file:
                    self.assertEqual(tmp_file.read(), test_config)
                raise Exception('Normal')
        except AssertionError:  # nocv
            raise
        except Exception:
            pass

        with utils.tmp_file_context() as file:
            with open(file.name, 'w') as output:
                with utils.redirect_stdany(output):
                    print("Test")
            with open(file.name, 'r') as output:
                self.assertEqual(output.read(), "Test\n")
コード例 #2
0
 def get_generated_vars(self):
     tmp = None
     obj_vars = self.get_vars()
     if "ansible_ssh_private_key_file" in obj_vars:
         tmp = tmp_file()
         tmp.write(obj_vars["ansible_ssh_private_key_file"])
         obj_vars["ansible_ssh_private_key_file"] = tmp.name
     return obj_vars, tmp
コード例 #3
0
 def get_generated_vars(self, tmp_dir='/tmp') -> Tuple[Dict, List]:
     files = []
     obj_vars = self.get_vars()
     if "ansible_ssh_private_key_file" in obj_vars:
         tmp = tmp_file(dir=tmp_dir)
         tmp.write(obj_vars["ansible_ssh_private_key_file"])
         obj_vars["ansible_ssh_private_key_file"] = tmp.name
         files.append(tmp)
     return dict(obj_vars), files
コード例 #4
0
ファイル: vars.py プロジェクト: teazj/polemarch
 def get_generated_vars(self):
     files = []
     obj_vars = self.get_vars()
     if "ansible_ssh_private_key_file" in obj_vars:
         tmp = tmp_file()
         tmp.write(obj_vars["ansible_ssh_private_key_file"])
         obj_vars["ansible_ssh_private_key_file"] = tmp.name
         files.append(tmp)
     return dict(obj_vars), files
コード例 #5
0
 def __generate_arg_file(self, value: Text) -> Tuple[Text, List[tmp_file]]:
     file = tmp_file(value, dir=self.cwd)
     return file.name, [file]
コード例 #6
0
 def file(self) -> Union[tmp_file, Text]:
     self._file = self._file or tmp_file(self.raw, dir=self.tmpdir)
     return self._file
コード例 #7
0
ファイル: utils.py プロジェクト: xtha/polemarch
 def __generate_arg_file(self, value):
     file = tmp_file(value)
     return file.name, [file]
コード例 #8
0
ファイル: utils.py プロジェクト: xtha/polemarch
 def file(self):
     self._file = self._file or tmp_file(self.raw)
     return self._file
コード例 #9
0
ファイル: utils.py プロジェクト: xtha/polemarch
 def test_magic_enter_exit(self):
     tmp = tmp_file(mode="r")
     with tmp as test_tmp_file:
         self.assertEqual(test_tmp_file, tmp)
     tmp = tmp_file(mode="r")
     self.assertEqual(tmp.__exit__(ValueError, 22, "Traceback"), False)