当前位置: 首页>>代码示例>>Python>>正文


Python TempDirectory.cleanup方法代码示例

本文整理汇总了Python中testfixtures.TempDirectory.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python TempDirectory.cleanup方法的具体用法?Python TempDirectory.cleanup怎么用?Python TempDirectory.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testfixtures.TempDirectory的用法示例。



在下文中一共展示了TempDirectory.cleanup方法的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: Test_SnapshotArchive_Repository

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_SnapshotArchive_Repository(TestCase):
    def setUp(self):
        store = MemoryCommitStorage()
        self.repo = BBRepository(store)
        self.tempdir = TempDirectory()
        self.setup_archive_a_snapshot()

    def setup_archive_a_snapshot(self):
        archive_name = 'somearchive.tgz'
        self.archive_contents = '123'
        self.archive_path = self.tempdir.write(archive_name,
            self.archive_contents)
        self.tag = generate_tag()
        self.first_WAL = '01234'
        self.last_WAL = '45678'
        commit_snapshot_to_repository(self.repo, self.archive_path, self.tag,
            self.first_WAL, self.last_WAL)

    def tearDown(self):
        self.tempdir.cleanup()

    def test_can_retrieve_snapshot_contents_with_tag(self):
        commit = [i for i in self.repo][-1]
        restore_path = self.tempdir.getpath('restorearchive.tgz')
        commit.get_contents_to_filename(restore_path)
        self.assertEqual(self.archive_contents,
            open(restore_path, 'rb').read())

    def test_get_first_WAL_file_for_archived_snapshot_with_tag(self):
        self.assertEqual(self.first_WAL, get_first_WAL(self.repo, self.tag))

    def test_get_last_WAL_file_for_archived_snapshot_with_tag(self):
        self.assertEqual(self.last_WAL, get_last_WAL(self.repo, self.tag))
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:35,代码来源:test_archivepgsql_repository.py


示例2: Test_archivewal_requires_WAL_file

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_archivewal_requires_WAL_file(TestCase):
    def setUp(self):
        self.tempdir = TempDirectory()
        self.config_dict = {
            'General': {
                'pgsql_data_directory': self.tempdir.path,
            },
        }
        self.config_file = os.path.join(self.tempdir.path, 'config_file')
        write_config_to_filename(self.config_dict, self.config_file)
        parser, self.options, self.args = archivewal_parse_args(['-c',
            self.config_file])

    def tearDown(self):
        self.tempdir.cleanup()

    def test_will_raise_exception_with_no_WAL_file(self):

        def will_raise_Exception():
            archivewal_validate_options_and_args(self.options, [])
        self.assertRaises(Exception, will_raise_Exception)

    def test_exception_is_explicit_about_error(self):
        try:
            archivewal_validate_options_and_args(self.options, [])
        except Exception, e:
            print 'Exception', e
            self.assertTrue('path to a WAL file' in str(e))
        else:
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:31,代码来源:test_archivewal_option_parsing.py


示例3: test_orders_stop

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
    def test_orders_stop(self, name, order_data, event_data, expected):
        tempdir = TempDirectory()
        try:
            data = order_data
            data['sid'] = self.ASSET133

            order = Order(**data)

            assets = {
                133: pd.DataFrame({
                    "open": [event_data["open"]],
                    "high": [event_data["high"]],
                    "low": [event_data["low"]],
                    "close": [event_data["close"]],
                    "volume": [event_data["volume"]],
                    "dt": [pd.Timestamp('2006-01-05 14:31', tz='UTC')]
                }).set_index("dt")
            }

            write_bcolz_minute_data(
                self.env,
                pd.date_range(
                    start=normalize_date(self.minutes[0]),
                    end=normalize_date(self.minutes[-1])
                ),
                tempdir.path,
                assets
            )

            equity_minute_reader = BcolzMinuteBarReader(tempdir.path)

            data_portal = DataPortal(
                self.env,
                equity_minute_reader=equity_minute_reader,
            )

            slippage_model = VolumeShareSlippage()

            try:
                dt = pd.Timestamp('2006-01-05 14:31', tz='UTC')
                bar_data = BarData(data_portal,
                                   lambda: dt,
                                   'minute')
                _, txn = next(slippage_model.simulate(
                    bar_data,
                    self.ASSET133,
                    [order],
                ))
            except StopIteration:
                txn = None

            if expected['transaction'] is None:
                self.assertIsNone(txn)
            else:
                self.assertIsNotNone(txn)

                for key, value in expected['transaction'].items():
                    self.assertEquals(value, txn[key])
        finally:
            tempdir.cleanup()
开发者ID:AdaoSmith,项目名称:zipline,代码行数:62,代码来源:test_slippage.py


示例4: WithTempDir

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class WithTempDir(object):

    def setUp(self):
        self.dir = TempDirectory()

    def tearDown(self):
        self.dir.cleanup()
开发者ID:Simplistix,项目名称:archivist,代码行数:9,代码来源:test_config.py


示例5: Test_incorrect_invocation

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_incorrect_invocation(TestCase):
    mainMsg = '''You have invoked this script as bbpgsql.
This script is supposed to be invoked through the commands archivepgsql
and archivewal.  Please check with your adminstrator to make sure these
commands were installed correctly.
'''
    unknownMsg = 'Unknown command: unknown\n'

    def setUp(self):
        self.tempdir = TempDirectory()
        self.config_dict = {
        }
        self.config_path = os.path.join(self.tempdir.path, 'config.ini')
        write_config_to_filename(self.config_dict, self.config_path)

    def tearDown(self):
        self.tempdir.cleanup()

    @patch('bbpgsql.bbpgsql_main.exit')
    def test_invocation_using_main_script_fails(self,
        mock_exit):
        bbpgsql_main(['bbpgsql', '-c', self.config_path])
        mock_exit.assert_called_with(1)

    @patch('bbpgsql.bbpgsql_main.stdout.write')
    @patch('bbpgsql.bbpgsql_main.exit')
    def test_invocation_using_unknown_fails(self,
        mock_exit, mock_stdout_write):
        bbpgsql_main(['unknown'])
        mock_stdout_write.assert_called_once_with(self.unknownMsg)
        mock_exit.assert_called_once_with(1)
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:33,代码来源:test_command_dispatch.py


示例6: test_atexit

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
    def test_atexit(self):
        # http://bugs.python.org/issue25532
        from testfixtures.mock import call

        m = Mock()
        with Replacer() as r:
            # make sure the marker is false, other tests will
            # probably have set it
            r.replace('testfixtures.TempDirectory.atexit_setup', False)
            r.replace('atexit.register', m.register)

            d = TempDirectory()

            expected = [call.register(d.atexit)]

            compare(expected, m.mock_calls)

            with catch_warnings(record=True) as w:
                d.atexit()
                self.assertTrue(len(w), 1)
                compare(str(w[0].message), (  # pragma: no branch
                    "TempDirectory instances not cleaned up by shutdown:\n" +
                    d.path
                    ))

            d.cleanup()

            compare(set(), TempDirectory.instances)

            # check re-running has no ill effects
            d.atexit()
开发者ID:Simplistix,项目名称:testfixtures,代码行数:33,代码来源:test_tempdirectory.py


示例7: test_cleanup

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
 def test_cleanup(self):
     d = TempDirectory()
     p = d.path
     assert os.path.exists(p) is True
     p = d.write('something', b'stuff')
     d.cleanup()
     assert os.path.exists(p) is False
开发者ID:Simplistix,项目名称:testfixtures,代码行数:9,代码来源:test_tempdirectory.py


示例8: Test_archivewal_parse_arges_returns_parser_options_args

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_archivewal_parse_arges_returns_parser_options_args(TestCase):
    def setUp(self):
        self.tempdir = TempDirectory()
        self.config_dict = {
            'General': {
                'pgsql_data_directory': self.tempdir.path,
            },
        }
        self.config_file = os.path.join(self.tempdir.path, 'config_file')
        write_config_to_filename(self.config_dict, self.config_file)

    def tearDown(self):
        self.tempdir.cleanup()

    def test_archivewal_parse_args_returns_three_items(self):
        item1, item2, item3 = archivewal_parse_args(args=['walfilename'])
        self.assertNotEqual(type(item1), type(None))
        self.assertNotEqual(type(item2), type(None))
        self.assertNotEqual(type(item3), type(None))

    def test_archivewal_parse_args_returns_parser(self):
        parser, item2, item3 = archivewal_parse_args(args=['walfilename'])
        self.assertTrue(isinstance(parser, OptionParser))

    def test_archivewal_parse_args_returns_options(self):
        item1, options, item3 = archivewal_parse_args(args=['walfilename'])
        self.assertTrue(isinstance(options, object))

    def test_archivewal_parse_args_returns_args(self):
        item1, item2, args = archivewal_parse_args(args=['walfilename'])
        self.assertEqual(type(args), type([]))
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:33,代码来源:test_archivewal_option_parsing.py


示例9: Test_archivepgsql_backup_invocation

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_archivepgsql_backup_invocation(TestCase):
    ARCHIVEPGSQL_PATH = os.path.join('bbpgsql', 'cmdline_scripts')
    CONFIG_FILE = 'config.ini'
    exe_script = 'archivepgsql'

    def setUp(self):
        self.setup_environment()
        self.setup_config()
        self.execution_sequence = 0

    def setup_environment(self):
        self.env = deepcopy(os.environ)
        self.env['PATH'] = ''.join([
            self.env['PATH'],
            ':',
            self.ARCHIVEPGSQL_PATH])
        self.tempdir = TempDirectory()
        self.data_dir = self.tempdir.makedir('pgsql_data')
        self.archive_dir = self.tempdir.makedir('pgsql_archive')

    def setup_config(self):
        self.config_path = os.path.join(self.tempdir.path, self.CONFIG_FILE)
        self.config_dict = {
            'General': {
                'pgsql_data_directory': self.data_dir,
            },
            'Snapshot': {
                'driver': 'memory',
            },
        }
        write_config_to_filename(self.config_dict, self.config_path)
        self.config = get_config_from_filename_and_set_up_logging(
            self.config_path
        )

    def tearDown(self):
        self.tempdir.cleanup()

    @patch('bbpgsql.archive_pgsql.commit_snapshot_to_repository')
    @patch('bbpgsql.archive_pgsql.create_archive')
    @patch('bbpgsql.archive_pgsql.pg_stop_backup')
    @patch('bbpgsql.archive_pgsql.pg_start_backup')
    def test_perform_backup(self, mock_pg_start_backup, mock_pg_stop_backup,
        mock_create_archive, mock_commit_snapshot_to_repository):
        first_WAL = '000000D0'
        second_WAL = '000000D1'
        mock_pg_start_backup.return_value = first_WAL
        mock_pg_stop_backup.return_value = second_WAL
        archiveFile = os.path.join(self.archive_dir, 'pgsql.snapshot.tar')
        tag = bbpgsql.archive_pgsql.generate_tag()
        repo = get_Snapshot_repository(self.config)
        bbpgsql.archive_pgsql.perform_backup(self.data_dir,
            archiveFile, tag, repo)
        mock_pg_start_backup.assert_called_once_with(tag)
        mock_create_archive.assert_called_once_with(self.data_dir, archiveFile)
        self.assertEqual(mock_pg_stop_backup.called, True)
        self.assertEqual(mock_pg_stop_backup.call_count, 1)
        mock_commit_snapshot_to_repository.assert_called_once_with(
            repo, archiveFile, tag, first_WAL, second_WAL)
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:61,代码来源:test_cmdline.py


示例10: test_atexit

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
 def test_atexit(self):
     d = TempDirectory()
     self.assertTrue(TempDirectory.atexit in [t[0] for t in atexit._exithandlers])
     with catch_warnings(record=True) as w:
         d.atexit()
         self.assertTrue(len(w), 1)
         compare(str(w[0].message), ("TempDirectory instances not cleaned up by shutdown:\n" + d.path))
     d.cleanup()
     # call again to make sure nothing blows up:
     d.atexit()
开发者ID:yoyossy,项目名称:testfixtures__Simplistix,代码行数:12,代码来源:test_tempdirectory.py


示例11: MailTestCaseMixin

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class MailTestCaseMixin(TestCase):

    def _pre_setup(self):
        super(MailTestCaseMixin, self)._pre_setup()
        self.tempdir = TempDirectory()
        self.settings_override = override_settings(
            MEDIA_ROOT=self.tempdir.path,
            EMAIL_BACKEND=u'poleno.mail.backend.EmailBackend',
            )
        self.settings_override.enable()

    def _post_teardown(self):
        self.settings_override.disable()
        self.tempdir.cleanup()
        super(MailTestCaseMixin, self)._post_teardown()


    def _call_with_defaults(self, func, kwargs, defaults):
        omit = kwargs.pop(u'omit', [])
        defaults.update(kwargs)
        for key in omit:
            defaults.pop(key, None)
        return func(**defaults)

    def _create_attachment(self, **kwargs):
        content = kwargs.pop(u'content', u'Default Testing Content')
        return self._call_with_defaults(Attachment.objects.create, kwargs, {
            u'file': ContentFile(content, name=u'overriden-file-name.bin'),
            u'name': u'default_testing_filename.txt',
            u'content_type': u'text/plain',
            })

    def _create_recipient(self, **kwargs):
        return self._call_with_defaults(Recipient.objects.create, kwargs, {
            u'name': u'Default Testing Name',
            u'mail': u'[email protected]',
            u'type': Recipient.TYPES.TO,
            u'status': Recipient.STATUSES.INBOUND,
            u'status_details': u'',
            u'remote_id': u'',
            })

    def _create_message(self, **kwargs):
        return self._call_with_defaults(Message.objects.create, kwargs, {
            u'type': Message.TYPES.INBOUND,
            u'processed': utc_now(),
            u'from_name': u'Default Testing From Name',
            u'from_mail': u'[email protected]',
            u'received_for': u'[email protected]',
            u'subject': u'Default Testing Subject',
            u'text': u'Default Testing Text Content',
            u'html': u'<p>Default Testing HTML Content</p>',
            u'headers': {'X-Default-Testing-Extra-Header': 'Default Testing Value'},
            })
开发者ID:gitter-badger,项目名称:chcemvediet,代码行数:56,代码来源:__init__.py


示例12: setUp

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class TestFixtureLoad:
    def setUp(self):
        self.d = TempDirectory()
        fixtureload.set_source_dir(self.d.path)
        self.d.write('test.json',
                json.dumps(
                    {
                        'description':
                            {
                                'samples': {
                                    'fixture0': {'a': 'b'},
                                    'fixture1': {'c': 'd'}
                                }
                            }
                    }
                ))
        self.d.write('test_corrupted.json', 'corrupted json')

    def tearDown(self):
        self.d.cleanup()

    def test_can_set_fixture_source_directory(self):
        fixtureload.set_source_dir('/tmp')
        assert fixtureload.fixture_source_dir == '/tmp'

    def test_can_load_fixture(self):
        fixture = fixtureload.load('test/description/fixture0')
        compare(fixture, {'a': 'b'})
        fixture = fixtureload.load('test/description/fixture1')
        compare(fixture, {'c': 'd'})

    def test_load_fixture_with_not_existed_file_should_raise(self):
        with ShouldRaise(IOError):
            fixtureload.load('not_existed/description/fixture0')

    def test_load_fixture_with_corrupted_file_should_raise(self):
        with ShouldRaise(ValueError):
            fixtureload.load('test_corrupted/description/fixture0')

    def test_parse_fixture_path(self):
        path = fixtureload.parse_fixture_path('test/desc/fixture0')
        compare(
            path,
            {
                'source_file': 'test.json',
                'fixture_desc': 'desc',
                'fixture': 'fixture0'
            }
        )

    def test_parse_fixture_path_if_path_is_not_valid(self):
        with ShouldRaise(ValueError('Fixture Path is not valid (testfixture0)')):
            fixtureload.parse_fixture_path('testfixture0')
开发者ID:ozanturksever,项目名称:fixtureload,代码行数:55,代码来源:test_fixtureload.py


示例13: Test_OptionParsing_and_Validation

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_OptionParsing_and_Validation(TestCase):
    def setUp(self):
        self.tempdir = TempDirectory()
        self.config_dict = {
        }
        self.config_path = os.path.join(self.tempdir.path, 'config.ini')
        write_config_to_filename(self.config_dict, self.config_path)

    def tearDown(self):
        self.tempdir.cleanup()

    def test_non_destructive_with_sys_argv(self):
        expected_sys_argv = ['', '-c', self.config_path]
        sys.argv = expected_sys_argv[:]
        non_destructive_minimal_parse_and_validate_args()
        self.assertEqual(expected_sys_argv, sys.argv)

    def test_validation_raises_exception_if_config_file_does_not_exist(self):
        def validate():
            parser, options, args = common_parse_args(args=[
                '--config', '/tmp/blah/blah/bbpgsql.ini'])
            common_validate_options_and_args(options, args)
        self.assertRaises(Exception, validate)

    def test_validation_raises_exception_if_config_file_permissions_too_open(
        self):
        with TempDirectory() as d:
            self.parent_dir = d.makedir('parent_dir')
            self.config_path = d.write('parent_dir/config.ini', '')
            self.open_perm = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO
            os.chmod(self.config_path, self.open_perm)

            def validate(config_path):
                parser, options, args = common_parse_args(args=[
                    '--config', config_path])
                common_validate_options_and_args(options, args)
            self.assertRaises(Exception, validate, self.config_path)

    def test_options_validate_if_config_file_exists(self):
        parser, options, args = common_parse_args(args=[
            '--config', self.config_path])
        self.assertTrue(common_validate_options_and_args(options, args))

    def test_validation_raises_exception_if_cannot_read_config_file(self):
        def validate():
            parser, options, args = common_parse_args(args=[
                '--config', self.config_path])
            self.no_perm = 0
            os.chmod(self.config_path, self.no_perm)
            common_validate_options_and_args(options, args)
        self.assertRaises(Exception, validate)
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:53,代码来源:test_option_parsing.py


示例14: TranslationLoaderTest

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class TranslationLoaderTest(TestCase):
    u"""
    Tests ``TranslationLoader`` template loader. Checks that the loader loads original template
    only if there is no translated template for the active language. If there is a translated
    template for the active languate, the loader loads this translated template. Also tests that an
    exception is raised if there is no original nor translated template.
    """

    def setUp(self):
        self.tempdir = TempDirectory()

        self.settings_override = override_settings(
            LANGUAGES=((u'de', u'Deutsch'), (u'en', u'English'), (u'fr', u'Francais')),
            TEMPLATE_LOADERS=((u'poleno.utils.template.TranslationLoader', u'django.template.loaders.filesystem.Loader'),),
            TEMPLATE_DIRS=(self.tempdir.path,),
            )
        self.settings_override.enable()

        self.tempdir.write(u'first.html', u'(first.html)\n')
        self.tempdir.write(u'first.en.html', u'(first.en.html)\n')
        self.tempdir.write(u'second.de.html', u'(second.de.html)\n')

    def tearDown(self):
        self.settings_override.disable()
        self.tempdir.cleanup()


    def test_translated_template_has_priority(self):
        # Existing: first.html, first.en.html
        with translation(u'en'):
            rendered = squeeze(render_to_string(u'first.html'))
            self.assertEqual(rendered, u'(first.en.html)')

    def test_with_only_translated_template(self):
        # Existing: second.de.html
        # Missing: second.html
        with translation(u'de'):
            rendered = squeeze(render_to_string(u'second.html'))
            self.assertEqual(rendered, u'(second.de.html)')

    def test_with_only_untranslated_template(self):
        # Existing: first.html
        # Missing: first.de.html
        with translation(u'de'):
            rendered = squeeze(render_to_string(u'first.html'))
            self.assertEqual(rendered, u'(first.html)')

    def test_missing_template_raises_exception(self):
        # Missing: second.html, second.en.html
        with self.assertRaises(TemplateDoesNotExist):
            render_to_string(u'second.html')
开发者ID:gitter-badger,项目名称:chcemvediet,代码行数:53,代码来源:test_template.py


示例15: HomeDirTest

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class HomeDirTest(unittest.TestCase):

    def setUp(self):
        self.temp_dir = TempDirectory(create=True)
        self.home = PathHomeDir(self.temp_dir.path)

    def tearDown(self):
        self.temp_dir.cleanup()

    def test_read(self):
        self.temp_dir.write("filename", "contents")
        self.assertEquals(self.home.read("filename"), "contents")

    def test_write(self):
        self.temp_dir.write("existing_file", "existing_contents")
        self.home.write("new_file", "contents")
        self.home.write("existing_file", "new_contents")
        self.assertEquals(self.temp_dir.read("existing_file"),
                          "new_contents")
        self.assertEquals(self.temp_dir.read("new_file"), "contents")

    def test_config_file(self):
        with collect_outputs() as outputs:
            self.home.write_config_file("new config")
            self.temp_dir.check(".cosmosrc")
            self.assertEquals(self.home.read_config_file(), "new config")
            self.assertIn("Settings saved", outputs.stdout.getvalue())
            file_mode = os.stat(self.temp_dir.getpath(".cosmosrc")).st_mode
            self.assertEquals(file_mode, stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR)

    def test_override_config_file(self):
        with collect_outputs():
            other_config = self.temp_dir.write("path/other", "config")
            self.assertEquals(
                self.home.read_config_file(filename_override=other_config),
                "config")

    def test_warn_on_unprotected_config_file(self):
        with collect_outputs() as outputs:
            self.home.write_config_file("new config")
            config_path = self.temp_dir.getpath(".cosmosrc")
            os.chmod(config_path, 0777)
            self.home.read_config_file()
            assertFunc = (self.assertNotIn if os.name=='nt' else self.assertIn)
            assertFunc("WARNING", outputs.stderr.getvalue())

    def test_last_cluster(self):
        self.home.write_last_cluster("0000000")
        self.temp_dir.check(".cosmoslast")
        self.assertEquals(self.home.read_last_cluster(), "0000000")
开发者ID:adamosloizou,项目名称:fiware-cosmos-platform,代码行数:52,代码来源:test_home_dir.py


示例16: copySpecialTestCase

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class copySpecialTestCase(unittest.TestCase):

    def setUp(self):
        self.inputDirectory = []
        self.specialFilesNamesAbsolutePath = []
        self.specialFileNames =[]
        self.inputDirectoriesPath = []
        for i in range(0,2):
            self.inputDirectory.append(TempDirectory())
            self.inputDirectory[i].write('india__{0}{0}{0}__.txt'.format(i), 'some foo thing')
            self.inputDirectory[i].write('god__{0}{0}{0}__.txt'.format(i), 'some foo thing')
            self.inputDirectory[i].write('hi.txt', 'some foo thing')

            self.specialFilesNamesAbsolutePath.append('{0}/india__{1}{1}{1}__.txt'.format(self.inputDirectory[i].path, i))
            self.specialFilesNamesAbsolutePath.append('{0}/god__{1}{1}{1}__.txt'.format(self.inputDirectory[i].path, i))
            self.specialFileNames.append('india__{0}{0}{0}__.txt'.format(i))
            self.specialFileNames.append('god__{0}{0}{0}__.txt'.format(i))
            self.inputDirectoriesPath.append(self.inputDirectory[i].path)

        self.outputDirectory = TempDirectory()
        self.outputDirectory.path = self.outputDirectory.path

    def test_getSpecialFilesNames(self):
        copySpecialFiles = CopySpecialFiles()
        for path in self.inputDirectoriesPath:
            copySpecialFiles.specialFileNames.extend(copySpecialFiles.getSpecialFilesNames(path))
        self.assertEqual(sorted(self.specialFilesNamesAbsolutePath), sorted(copySpecialFiles.specialFileNames))

    def test_copyToDirectory(self):
        copySpecialFiles = CopySpecialFiles()
        for path in self.inputDirectoriesPath:
            copySpecialFiles.specialFileNames.extend(copySpecialFiles.getSpecialFilesNames(path))
        copySpecialFiles.outputDirectory = self.outputDirectory.path
        copySpecialFiles.copyToDirectory()
        self.assertEqual(sorted(os.listdir(self.outputDirectory.path)), sorted(self.specialFileNames))

    def test_copyToZip(self):
        copySpecialFiles = CopySpecialFiles()
        for path in self.inputDirectoriesPath:
            copySpecialFiles.specialFileNames.extend(copySpecialFiles.getSpecialFilesNames(path))
        copySpecialFiles.zipFile = "dummy.zip"
        copySpecialFiles.copyToZip()
        with zipfile.ZipFile('dummy.zip', 'r') as myzip:
            self.assertEqual(sorted(myzip.namelist()), sorted(self.specialFileNames))
        os.remove("dummy.zip")

    def tearDown(self):
        for inputDirectory in self.inputDirectory:
            inputDirectory.cleanup()
        self.outputDirectory.cleanup()
开发者ID:thangabalu,项目名称:Helloworld,代码行数:52,代码来源:copyspecialtest.py


示例17: Test_FilesystemCommitStorage

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_FilesystemCommitStorage(TestCase):
    def setUp(self):
        self.tempdir = TempDirectory()
        self.commit_storage_path = self.tempdir.makedir('commit_storage')
        self.config = config()
        self.config.set('WAL', 'driver', 'filesystem')
        self.config.set('WAL', 'path', self.commit_storage_path)

    def tearDown(self):
        self.tempdir.cleanup()

    def test_will_build_storage_from_config(self):
        self.assertEqual(FilesystemCommitStorage,
            type(get_repository_storage_from_config(self.config, 'WAL')))
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:16,代码来源:test_storage_configuration.py


示例18: test_dont_cleanup_with_path

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
 def test_dont_cleanup_with_path(self):
     d = mkdtemp()
     fp = os.path.join(d, "test")
     with open(fp, "w") as f:
         f.write("foo")
     try:
         td = TempDirectory(path=d)
         self.assertEqual(d, td.path)
         td.cleanup()
         # checks
         self.assertEqual(os.listdir(d), ["test"])
         with file(fp) as f:
             self.assertEqual(f.read(), "foo")
     finally:
         rmtree(d)
开发者ID:yoyossy,项目名称:testfixtures__Simplistix,代码行数:17,代码来源:test_tempdirectory.py


示例19: test_dont_cleanup_with_path

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
 def test_dont_cleanup_with_path(self):
     d = mkdtemp()
     fp = os.path.join(d, 'test')
     with open(fp, 'w') as f:
         f.write('foo')
     try:
         td = TempDirectory(path=d)
         self.assertEqual(d, td.path)
         td.cleanup()
         # checks
         self.assertEqual(os.listdir(d), ['test'])
         with open(fp) as f:
             self.assertEqual(f.read(), 'foo')
     finally:
         rmtree(d)
开发者ID:Simplistix,项目名称:testfixtures,代码行数:17,代码来源:test_tempdirectory.py


示例20: Test_restorewal_requires_WAL_file_and_destination

# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import cleanup [as 别名]
class Test_restorewal_requires_WAL_file_and_destination(TestCase):
    def setUp(self):
        self.tempdir = TempDirectory()
        self.config_dict = {
            'General': {
                'pgsql_data_directory': self.tempdir.path,
            },
        }
        self.config_file = os.path.join(self.tempdir.path, 'config_file')
        write_config_to_filename(self.config_dict, self.config_file)
        parser, self.options, self.args = restorewal_parse_args(['-c',
            self.config_file])

    def tearDown(self):
        self.tempdir.cleanup()

    def test_will_raise_exception_if_not_exactly_two_args(self):
        self.assertRaises(
            Exception,
            restorewal_validate_options_and_args,
            self.options,
            []
            )
        self.assertRaises(
            Exception,
            restorewal_validate_options_and_args,
            self.options,
            ['one']
            )
        self.assertRaises(
            Exception,
            restorewal_validate_options_and_args,
            self.options,
            ['one', 'two', 'three']
            )

    def test_is_explicit_about_error(self):
        try:
            restorewal_validate_options_and_args(
                self.options,
                []
                )
        except Exception, e:
            print 'Exception', e
            self.assertTrue('name of the WAL file to retrieve' in str(e))
        else:
开发者ID:nbarendt,项目名称:PgsqlBackup,代码行数:48,代码来源:test_restorewal_option_parsing.py



注:本文中的testfixtures.TempDirectory.cleanup方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。