コード例 #1
0
ファイル: test_log.py プロジェクト: gaolichuang/py-essential
 def setUp(self):
     super(LogConfigTestCase, self).setUp()
     self.config = self.useFixture(config.Config()).config
     self.log_config_append = \
         fileutils.write_to_tempfile(content=self.minimal_config,
                                     prefix='logging',
                                     suffix='.conf'
                                     )
コード例 #2
0
    def test_file_without_path_and_suffix(self):
        res = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))
        self.assertTrue(tmpfile.startswith('tmp'))

        self.check_file_content(res)
コード例 #3
0
ファイル: test_log.py プロジェクト: gaolichuang/py-essential
 def test_log_config_append_invalid(self):
     self.log_config_append = \
         fileutils.write_to_tempfile(content=self.minimal_config[5:],
                                     prefix='logging',
                                     suffix='.conf'
                                     )
     self.config(log_config_append=self.log_config_append)
     self.assertRaises(log.LogConfigError, log.setup,
                       'test_log_config_append')
コード例 #4
0
    def test_file_with_not_default_prefix(self):
        prefix = 'test'
        res = fileutils.write_to_tempfile(self.content, prefix=prefix)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(tmpfile.startswith(prefix))
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))

        self.check_file_content(res)
コード例 #5
0
    def test_file_with_not_existing_path(self):
        path = '/tmp/testing/test1'
        res = fileutils.write_to_tempfile(self.content, path=path)
        self.assertTrue(os.path.exists(res))
        (basepath, tmpfile) = os.path.split(res)
        self.assertEqual(basepath, path)
        self.assertTrue(tmpfile.startswith('tmp'))

        self.check_file_content(res)
        shutil.rmtree('/tmp/testing')
コード例 #6
0
    def test_file_with_not_default_suffix(self):
        suffix = '.conf'
        res = fileutils.write_to_tempfile(self.content, suffix=suffix)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(basepath.startswith(tempfile.gettempdir()))
        self.assertTrue(tmpfile.startswith('tmp'))
        self.assertTrue(tmpfile.endswith('.conf'))

        self.check_file_content(res)
コード例 #7
0
    def test_file_with_not_existing_path_and_not_default_suffix(self):
        suffix = '.txt'
        path = '/tmp/testing/test2'
        res = fileutils.write_to_tempfile(self.content,
                                          path=path,
                                          suffix=suffix)
        self.assertTrue(os.path.exists(res))

        (basepath, tmpfile) = os.path.split(res)
        self.assertTrue(tmpfile.startswith('tmp'))
        self.assertEqual(basepath, path)
        self.assertTrue(tmpfile.endswith(suffix))

        self.check_file_content(res)
        shutil.rmtree('/tmp/testing')