• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testfixtures.TempDirectory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Test_archivewal_requires_WAL_file

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,代码行数:29,代码来源:test_archivewal_option_parsing.py


示例2: test_orders_stop

    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,代码行数:60,代码来源:test_slippage.py


示例3: Test_SnapshotArchive_Repository

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,代码行数:33,代码来源:test_archivepgsql_repository.py


示例4: TestPathSource

class TestPathSource(TestCase):

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

    def test_abc(self):
        self.assertTrue(issubclass(Plugin, Source))

    def test_schema_ok(self):
        p1 = self.dir.write('foo', b'f')
        p2 = self.dir.write('bar', b'b')
        compare(
            dict(type='paths', values=[p1, p2], repo='config'),
            Plugin.schema(
                dict(type='paths', values=[p1, p2], repo='config')
            ))

    def test_schema_wrong_type(self):
        text = "not a valid value for dictionary value @ data['type']"
        with ShouldFailSchemaWith(text):
            Plugin.schema(dict(type='bar', values=['/']))

    def test_schema_extra_keys(self):
        with ShouldFailSchemaWith("extra keys not allowed @ data['foo']"):
            Plugin.schema(dict(type='paths', foo='bar'))

    def test_name_supplied(self):
        text = "not a valid value for dictionary value @ data['name']"
        with ShouldFailSchemaWith(text):
            Plugin.schema(dict(type='paths', name='foo'))

    def test_no_paths(self):
        text = "length of value must be at least 1 for dictionary value " \
               "@ data['values']"
        with ShouldFailSchemaWith(text):
            Plugin.schema(dict(type='paths', values=[]))

    def test_path_not_string(self):
        text = "invalid list value @ data['values'][0]"
        with ShouldFailSchemaWith(text):
            Plugin.schema(dict(type='paths', values=[1]))

    def test_path_not_starting_with_slash(self):
        text = "invalid list value @ data['values'][0]"
        with ShouldFailSchemaWith(text):
            Plugin.schema(dict(type='paths', values=['foo']))

    def test_path_not_there(self):
        text = "invalid list value @ data['values'][0]"
        with ShouldFailSchemaWith(text):
            Plugin.schema(dict(type='paths', values=[self.dir.getpath('bad')]))

    def test_interface(self):
        plugin = Plugin('source', name=None, repo='config',
                        values=['/foo/bar'])
        compare(plugin.type, 'source')
        compare(plugin.name, None)
        compare(plugin.repo, 'config')
        compare(plugin.source_paths, ['/foo/bar'])
开发者ID:khchine5,项目名称:archivist,代码行数:60,代码来源:test_source_paths.py


示例5: WithTempDir

class WithTempDir(object):

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

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


示例6: test_activity

    def test_activity(self, fake_session_mock, fake_s3_mock, fake_key_mock,
                      mock_sqs_message, mock_sqs_connect):
        directory = TempDirectory()

        for testdata in self.do_activity_passes:

            fake_session_mock.return_value = FakeSession(test_data.PreparePost_session_example(
                testdata["update_date"]))
            mock_sqs_connect.return_value = FakeSQSConn(directory)
            mock_sqs_message.return_value = FakeSQSMessage(directory)
            fake_s3_mock.return_value = FakeS3Connection()
            self.activity_PreparePostEIF.logger = mock.MagicMock()
            self.activity_PreparePostEIF.set_monitor_property = mock.MagicMock()
            self.activity_PreparePostEIF.emit_monitor_event = mock.MagicMock()

            success = self.activity_PreparePostEIF.do_activity(test_data.PreparePostEIF_data)

            fake_sqs_queue = FakeSQSQueue(directory)
            data_written_in_test_queue = fake_sqs_queue.read(test_data.PreparePostEIF_test_dir)

            self.assertEqual(True, success)
            self.assertEqual(json.dumps(testdata["message"]), data_written_in_test_queue)

            output_json = json.loads(directory.read(test_data.PreparePostEIF_test_dir))
            expected = testdata["expected"]
            self.assertDictEqual(output_json, expected)
开发者ID:elifesciences,项目名称:elife-bot,代码行数:26,代码来源:test_activity_prepare_post_eif.py


示例7: Test_incorrect_invocation

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,代码行数:31,代码来源:test_command_dispatch.py


示例8: GitHelper

class GitHelper(object):

    repo = 'local/'

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

    def git(self, command, repo=None):
        repo_path = self.dir.getpath(repo or self.repo)
        try:
            return check_output(['git'] + command.split(), cwd=repo_path, stderr=STDOUT)
        except CalledProcessError as e:
            self.fail(e.output)

    def git_rev_parse(self, label, repo=None):
        return self.git('rev-parse --verify -q --short '+label, repo).strip()

    def check_tags(self, expected, repo=None):
        actual = {}
        for tag in self.git('tag', repo).split():
            actual[tag] = self.git_rev_parse(tag, repo)
        compare(expected, actual=actual)

    def make_repo_with_content(self, repo):
        if not os.path.exists(self.dir.getpath(repo)):
            self.dir.makedir(repo)
        self.git('init', repo)
        self.dir.write(repo + 'a', 'some content')
        self.dir.write(repo + 'b', 'other content')
        self.dir.write(repo + 'c', 'more content')
        self.git('add .', repo)
        self.git('commit -m initial', repo)
开发者ID:cjw296,项目名称:ansible-role-createtag,代码行数:33,代码来源:git.py


示例9: test_cleanup

 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,代码行数:7,代码来源:test_tempdirectory.py


示例10: Test_archivewal_parse_arges_returns_parser_options_args

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,代码行数:31,代码来源:test_archivewal_option_parsing.py


示例11: Test_archivepgsql_backup_invocation

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,代码行数:59,代码来源:test_cmdline.py


示例12: test_evaluate_read_same

 def test_evaluate_read_same(self):
     dir = TempDirectory()
     dir.write('foo', b'content')
     d = TestContainer('parsed',FileBlock('foo','content','read'))
     d.evaluate_with(Files('td'),globs={'td':dir})
     compare([C(FileResult,
                passed=True,
                expected=None,
                actual=None)],
             [r.evaluated for r in d])
开发者ID:nedbat,项目名称:testfixtures,代码行数:10,代码来源:test_manuel.py


示例13: test_inifile_discovery_should_ignore_invalid_files_without_raising_exception

    def test_inifile_discovery_should_ignore_invalid_files_without_raising_exception(self):
        root_dir = TempDirectory()
        self.tmpdirs.append(root_dir)

        cfg_file = root_dir.write(('some', 'strange', 'config.cfg'), '&ˆ%$#$%ˆ&*()(*&ˆ'.encode('utf8'))
        root_dir.write(('some', 'config.ini'), '$#%ˆ&*((*&ˆ%'.encode('utf8'))

        discovery = ConfigurationDiscovery(
            os.path.realpath(os.path.dirname(cfg_file)), filetypes=(IniFileConfigurationLoader, ))

        self.assertEqual(discovery.config_files,  [])
开发者ID:erickwilder,项目名称:prettyconf,代码行数:11,代码来源:test_filediscover.py


示例14: MailTestCaseMixin

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,代码行数:54,代码来源:__init__.py


示例15: test_create_monitor_with_watch_path

    def test_create_monitor_with_watch_path(self):
        wd = TempDirectory()
        source_path = wd.makedir('source')
        wd.makedir('build')

        with chdir(wd.path):
            m = create_monitor(source_path)
        assert len(m.reporters) == 1
        reporter = m.reporters[0]
        assert reporter.watch_path == source_path
        assert reporter.build_path == '{}-build'.format(os.path.realpath(source_path)) # noqa
开发者ID:yerejm,项目名称:ttt,代码行数:11,代码来源:test_monitor.py


示例16: test_evaulate_write

 def test_evaulate_write(self):
     dir = TempDirectory()
     d = TestContainer('parsed',FileBlock('foo','content','write'))
     d.evaluate_with(Files('td'),globs={'td':dir})
     compare([C(FileResult,
                passed=True,
                expected=None,
                actual=None)],
             [r.evaluated for r in d])
     dir.compare(['foo'])
     compare(dir.read('foo', 'ascii'), 'content')
开发者ID:nedbat,项目名称:testfixtures,代码行数:11,代码来源:test_manuel.py


示例17: test_evaluate_read_difference

 def test_evaluate_read_difference(self):
     dir = TempDirectory()
     dir.write('foo', b'actual')
     d = TestContainer('parsed',FileBlock('foo','expected','read'))
     d.evaluate_with(Files('td'),globs={'td':dir})
     compare([C(FileResult,
                passed=False,
                path='foo',
                expected='expected',
                actual='actual')],
             [r.evaluated for r in d])
开发者ID:nedbat,项目名称:testfixtures,代码行数:11,代码来源:test_manuel.py


示例18: tearDown

 def tearDown(self):
     """
     Delete all the temporary directories and files created during this
     testing session.
     """
     for replicate in range(1, 6):
         file_name = "original_mutated_%d.fasta" % replicate
         if os.path.exists(file_name):
             os.remove(file_name)
     if os.path.exists("original_snpListMutated.txt"):
         os.remove("original_snpListMutated.txt")
     TempDirectory.cleanup_all()
开发者ID:CFSAN-Biostatistics,项目名称:snp-mutator,代码行数:12,代码来源:test_snpmutator.py


示例19: test_activity

    def test_activity(self, mock_set_monitor_property, mock_emit_monitor_event, fake_s3_mock, fake_key_mock):
        directory = TempDirectory()

        fake_key_mock.return_value = FakeKey(directory, data.bucket_dest_file_name,
                                             data.RewriteEIF_json_input_string)
        fake_s3_mock.return_value = FakeS3Connection()

        success = self.activity_PreparePostEIF.do_activity(data.RewriteEIF_data)
        self.assertEqual(True, success)

        output_json = json.loads(directory.read(data.bucket_dest_file_name))
        expected = data.RewriteEIF_json_output
        self.assertDictEqual(output_json, expected)
开发者ID:elifesciences,项目名称:elife-bot,代码行数:13,代码来源:test_activity_rewrite_eif.py


示例20: test_cleanup_all

    def test_cleanup_all(self):
        d1 = TempDirectory()
        d2 = TempDirectory()

        assert os.path.exists(d1.path) is True
        p1 = d1.path
        assert os.path.exists(d2.path) is True
        p2 = d2.path

        TempDirectory.cleanup_all()

        assert os.path.exists(p1) is False
        assert os.path.exists(p2) is False
开发者ID:Simplistix,项目名称:testfixtures,代码行数:13,代码来源:test_tempdirectory.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python popen.MockPopen类代码示例发布时间:2022-05-27
下一篇:
Python testfixtures.Replacer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap