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


Python testfixtures.TempDirectory方法代码示例

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


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

示例1: setUpClass

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def setUpClass(cls):
        cls.test_data_dir = TempDirectory()
        cls.db_path = cls.test_data_dir.getpath('adjustments.db')
        all_days = TradingEnvironment().trading_days
        cls.calendar_days = all_days[
            all_days.slice_indexer(TEST_CALENDAR_START, TEST_CALENDAR_STOP)
        ]
        daily_bar_reader = MockDailyBarSpotReader()
        writer = SQLiteAdjustmentWriter(cls.db_path, cls.calendar_days,
                                        daily_bar_reader)
        writer.write(SPLITS, MERGERS, DIVIDENDS)

        cls.assets = TEST_QUERY_ASSETS
        cls.asset_info = EQUITY_INFO
        cls.bcolz_writer = SyntheticDailyBarWriter(
            cls.asset_info,
            cls.calendar_days,
        )
        cls.bcolz_path = cls.test_data_dir.getpath('equity_pricing.bcolz')
        cls.bcolz_writer.write(cls.bcolz_path, cls.calendar_days, cls.assets) 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:22,代码来源:test_us_equity_pricing_loader.py

示例2: test_copydir

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_copydir():
    """Test copydir."""
    example_file = b'example file content'
    with TempDirectory() as tmp_dir:
        dest_path = tmp_dir.makedir('dest')
        src_path = tmp_dir.makedir('src')
        tmp_dir.makedir(('src', 'lib'))
        tmp_dir.write(('src', 'example_file'), example_file)
        tmp_dir.write(('src', 'lib', 'example_file'), example_file)

        copydir(src_path, dest_path, '**')

        assert tmp_dir.read(('src', 'example_file')) == example_file
        assert tmp_dir.read(('src', 'lib', 'example_file')) == example_file
        assert tmp_dir.read(('dest', 'example_file')) == example_file
        assert tmp_dir.read(('dest', 'lib', 'example_file')) == example_file 
开发者ID:onicagroup,项目名称:runway,代码行数:18,代码来源:test_aws_lambda.py

示例3: test_create

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_create(self):
        with TempDirectory() as tmpdir:
            rmtree(tmpdir.path)  # needs to be non-existent for the script
            self.run_script(['-o', tmpdir.path])

            tmpdir.check('sitemap-0.xml', 'sitemap.xml')

            xml_index = ET.parse(os.path.join(tmpdir.path, 'sitemap.xml'))
            ns = {'ns0': 'http://www.sitemaps.org/schemas/sitemap/0.9'}
            locs = [loc.text for loc in xml_index.findall('ns0:sitemap/ns0:loc', ns)]
            assert_in('http://localhost/allura_sitemap/sitemap-0.xml', locs)

            xml_0 = ET.parse(os.path.join(tmpdir.path, 'sitemap-0.xml'))
            urls = [loc.text for loc in xml_0.findall('ns0:url/ns0:loc', ns)]
            assert_in('http://localhost/p/wiki/', urls)
            assert_in('http://localhost/p/test/sub1/', urls) 
开发者ID:apache,项目名称:allura,代码行数:18,代码来源:test_create_sitemap_files.py

示例4: test_ServerDefinitionFile_init

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_ServerDefinitionFile_init(testcase, sd_file_data):
    # pylint: disable=unused-argument
    """
    Test function for ServerDefinitionFile.__init__()
    """

    with TempDirectory() as tmp_dir:

        # Create the server definition file
        fd_filename = 'tmp_server_definition_file.yml'
        sd_filepath = os.path.join(tmp_dir.path, fd_filename)
        if isinstance(sd_file_data, six.text_type):
            sd_file_data = sd_file_data.encode('utf-8')
        tmp_dir.write(fd_filename, sd_file_data)

        # The code to be tested
        ServerDefinitionFile(filepath=sd_filepath) 
开发者ID:pywbem,项目名称:pywbem,代码行数:19,代码来源:test_server_definition_file.py

示例5: setUp

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def setUp(self):

        self.asset_info = EQUITY_INFO
        self.writer = SyntheticDailyBarWriter(
            self.asset_info,
            self.trading_days,
        )

        self.dir_ = TempDirectory()
        self.dir_.create()
        self.dest = self.dir_.getpath('daily_equity_pricing.bcolz') 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:13,代码来源:test_us_equity_pricing.py

示例6: setUp

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def setUp(self):

        self.dir_ = TempDirectory()
        self.dir_.create()
        self.dest = self.dir_.getpath('minute_bars')
        os.makedirs(self.dest)
        self.writer = BcolzMinuteBarWriter(
            TEST_CALENDAR_START,
            self.dest,
            self.market_opens,
            self.market_closes,
            US_EQUITIES_MINUTES_PER_DAY,
        )
        self.reader = BcolzMinuteBarReader(self.dest) 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:16,代码来源:test_minute_bars.py

示例7: setUpClass

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def setUpClass(cls):
        cls.first_asset_start = Timestamp('2015-04-01', tz='UTC')
        cls.env = TradingEnvironment()
        cls.trading_day = day = cls.env.trading_day
        cls.calendar = date_range('2015', '2015-08', tz='UTC', freq=day)

        cls.asset_info = make_rotating_equity_info(
            num_assets=6,
            first_start=cls.first_asset_start,
            frequency=day,
            periods_between_starts=4,
            asset_lifetime=8,
        )
        cls.last_asset_end = cls.asset_info['end_date'].max()
        cls.all_asset_ids = cls.asset_info.index

        cls.env.write_data(equities_df=cls.asset_info)
        cls.finder = cls.env.asset_finder

        cls.temp_dir = TempDirectory()
        cls.temp_dir.create()

        try:
            cls.writer = SyntheticDailyBarWriter(
                asset_info=cls.asset_info[['start_date', 'end_date']],
                calendar=cls.calendar,
            )
            table = cls.writer.write(
                cls.temp_dir.getpath('testdata.bcolz'),
                cls.calendar,
                cls.all_asset_ids,
            )

            cls.pipeline_loader = USEquityPricingLoader(
                BcolzDailyBarReader(table),
                NullAdjustmentReader(),
            )
        except:
            cls.temp_dir.cleanup()
            raise 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:42,代码来源:test_engine.py

示例8: setUpClass

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def setUpClass(cls):
        cls.AAPL = 1
        cls.MSFT = 2
        cls.BRK_A = 3
        cls.assets = [cls.AAPL, cls.MSFT, cls.BRK_A]
        asset_info = make_simple_equity_info(
            cls.assets,
            Timestamp('2014'),
            Timestamp('2015'),
            ['AAPL', 'MSFT', 'BRK_A'],
        )
        cls.env = trading.TradingEnvironment()
        cls.env.write_data(equities_df=asset_info)
        cls.tempdir = tempdir = TempDirectory()
        tempdir.create()
        try:
            cls.raw_data, bar_reader = cls.create_bar_reader(tempdir)
            adj_reader = cls.create_adjustment_reader(tempdir)
            cls.pipeline_loader = USEquityPricingLoader(
                bar_reader, adj_reader
            )
        except:
            cls.tempdir.cleanup()
            raise

        cls.dates = cls.raw_data[cls.AAPL].index.tz_localize('UTC')
        cls.AAPL_split_date = Timestamp("2014-06-09", tz='UTC') 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:29,代码来源:test_pipeline_algo.py

示例9: _test_minute_data

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def _test_minute_data(self, algo_class):
        start_session = pd.Timestamp('2002-1-2', tz='UTC')
        period_end = pd.Timestamp('2002-1-4', tz='UTC')
        equities = pd.DataFrame([{
            'start_date': start_session,
            'end_date': period_end + timedelta(days=1),
            'exchange': "TEST",
        }] * 2)
        equities['symbol'] = ['A', 'B']
        with TempDirectory() as tempdir, \
                tmp_trading_env(equities=equities,
                                load=self.make_load_function()) as env:
            sim_params = SimulationParameters(
                start_session=start_session,
                end_session=period_end,
                capital_base=1.0e5,
                data_frequency='minute',
                trading_calendar=self.trading_calendar,
            )

            data_portal = create_data_portal(
                env.asset_finder,
                tempdir,
                sim_params,
                equities.index,
                self.trading_calendar,
            )
            algo = algo_class(sim_params=sim_params, env=env)
            algo.run(data_portal) 
开发者ID:enigmampc,项目名称:catalyst,代码行数:31,代码来源:test_algorithm.py

示例10: temp_directory_with_files

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def temp_directory_with_files(cls, files=ALL_FILES):
        """Create a temp directory with files."""
        temp_dict = TempDirectory()
        for file_ in files:
            temp_dict.write(file_, b'')
        return temp_dict 
开发者ID:onicagroup,项目名称:runway,代码行数:8,代码来源:test_aws_lambda.py

示例11: test_calculate_hash_diff_filename_same_contents

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_calculate_hash_diff_filename_same_contents(self):
        """Test calculate hash diff filename same contents."""
        files = ["file1.txt", "f2/file2.txt"]
        file1, file2 = files
        with TempDirectory() as temp_dir:
            root = temp_dir.path
            for file_name in files:
                temp_dir.write(file_name, b"data")
            hash1 = _calculate_hash([file1], root)
            hash2 = _calculate_hash([file2], root)
        self.assertNotEqual(hash1, hash2) 
开发者ID:onicagroup,项目名称:runway,代码行数:13,代码来源:test_aws_lambda.py

示例12: test_calculate_hash_different_ordering

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_calculate_hash_different_ordering(self):
        """Test calculate hash different ordering."""
        files1 = ALL_FILES
        files2 = random.sample(ALL_FILES, k=len(ALL_FILES))
        with TempDirectory() as temp_dir1:
            root1 = temp_dir1.path
            for file_name in files1:
                temp_dir1.write(file_name, b"")
            with TempDirectory() as temp_dir2:
                root2 = temp_dir2.path
                for file_name in files2:
                    temp_dir2.write(file_name, b"")
                hash1 = _calculate_hash(files1, root1)
                hash2 = _calculate_hash(files2, root2)
                self.assertEqual(hash1, hash2) 
开发者ID:onicagroup,项目名称:runway,代码行数:17,代码来源:test_aws_lambda.py

示例13: test_with_docker_file

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_with_docker_file(self):
        """Test with docker_file provided."""
        client = make_fake_client()
        with TempDirectory() as tmp_dir:
            docker_file = tmp_dir.write('Dockerfile', b'')
            dockerized_pip(os.getcwd(), client=client,
                           docker_file=docker_file)

            client.api.build.assert_called_with(
                path=tmp_dir.path,
                dockerfile='Dockerfile',
                forcerm=True
            )
            client.api.create_container.assert_called_with(
                detach=True,
                image=FAKE_IMAGE_ID,
                command=self.command,
                host_config=self.host_config
            )
            client.api.inspect_container.assert_called_with(FAKE_CONTAINER_ID)
            client.api.start.assert_called_with(FAKE_CONTAINER_ID)
            client.api.logs.assert_called_with(FAKE_CONTAINER_ID,
                                               stderr=True,
                                               stdout=True,
                                               stream=True,
                                               tail=0) 
开发者ID:onicagroup,项目名称:runway,代码行数:28,代码来源:test_aws_lambda.py

示例14: test_default

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_default(self):
        """Test default action."""
        expected = b'This is correct.'
        with TempDirectory() as tmp_dir:
            tmp_dir.write('Pipfile', self.PIPFILE.encode('utf-8'))
            tmp_dir.write('requirements.txt', expected)
            req_path = handle_requirements(package_root=tmp_dir.path,
                                           dest_path=tmp_dir.path,
                                           requirements=find_requirements(tmp_dir.path))

            assert req_path == os.path.join(tmp_dir.path, 'requirements.txt')
            assert not os.path.isfile(os.path.join(tmp_dir.path, 'Pipfile.lock'))
            assert tmp_dir.read('requirements.txt') == expected 
开发者ID:onicagroup,项目名称:runway,代码行数:15,代码来源:test_aws_lambda.py

示例15: test_implicit_pipenv

# 需要导入模块: import testfixtures [as 别名]
# 或者: from testfixtures import TempDirectory [as 别名]
def test_implicit_pipenv(self):
        """Test implicit use of pipenv."""
        with TempDirectory() as tmp_dir:
            tmp_dir.write('Pipfile', self.PIPFILE.encode('utf-8'))
            req_path = handle_requirements(package_root=tmp_dir.path,
                                           dest_path=tmp_dir.path,
                                           requirements=find_requirements(tmp_dir.path))

            assert req_path == os.path.join(tmp_dir.path, 'requirements.txt')
            assert tmp_dir.read('Pipfile.lock')
            assert tmp_dir.read('requirements.txt') == \
                b'-i https://pypi.org/simple\n\n' 
开发者ID:onicagroup,项目名称:runway,代码行数:14,代码来源:test_aws_lambda.py


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