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


Python local.LocalPath方法代码示例

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


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

示例1: test_resumable_pipeline_fit_transform_should_save_all_fitted_pipeline_steps

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_resumable_pipeline_fit_transform_should_save_all_fitted_pipeline_steps(tmpdir: LocalPath):
    p = ResumablePipeline([
        (SOME_STEP_1, MultiplyByN(multiply_by=2)),
        (PIPELINE_2, ResumablePipeline([
            (SOME_STEP_2, MultiplyByN(multiply_by=4)),
            (CHECKPOINT, DefaultCheckpoint()),
            (SOME_STEP_3, MultiplyByN(multiply_by=6))
        ]))
    ], cache_folder=tmpdir)
    p.name = ROOT

    p, outputs = p.fit_transform(
        np.array(range(10)),
        np.array(range(10))
    )

    not_saved_paths = [create_some_step3_path(tmpdir)]
    saved_paths = [create_root_path(tmpdir), create_pipeline2_path(tmpdir), create_some_step1_path(tmpdir),
                   create_some_step2_path(tmpdir), create_some_checkpoint_path(tmpdir)]
    assert np.array_equal(outputs, EXPECTED_OUTPUTS)
    for p in saved_paths:
        assert os.path.exists(p)
    for p in not_saved_paths:
        assert not os.path.exists(p) 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:26,代码来源:test_step_saving.py

示例2: test_resumable_pipeline_fit_should_save_all_fitted_pipeline_steps

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_resumable_pipeline_fit_should_save_all_fitted_pipeline_steps(tmpdir: LocalPath):
    p = ResumablePipeline([
        (SOME_STEP_1, MultiplyByN(multiply_by=2)),
        (PIPELINE_2, ResumablePipeline([
            (SOME_STEP_2, MultiplyByN(multiply_by=4)),
            (CHECKPOINT, DefaultCheckpoint()),
            (SOME_STEP_3, MultiplyByN(multiply_by=6))
        ]))
    ], cache_folder=tmpdir)
    p.name = ROOT

    p = p.fit(
        np.array(range(10)),
        np.array(range(10))
    )

    not_saved_paths = [create_some_step3_path(tmpdir)]
    saved_paths = [create_root_path(tmpdir), create_pipeline2_path(tmpdir), create_some_step1_path(tmpdir),
                   create_some_step2_path(tmpdir), create_some_checkpoint_path(tmpdir)]
    for p in saved_paths:
        assert os.path.exists(p)
    for p in not_saved_paths:
        assert not os.path.exists(p) 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:25,代码来源:test_step_saving.py

示例3: test_when_hyperparams_should_save_checkpoint_pickle

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_when_hyperparams_should_save_checkpoint_pickle(tmpdir: LocalPath):
    tape = TapeCallbackFunction()
    pickle_checkpoint_step = DefaultCheckpoint()
    pipeline = create_pipeline(tmpdir, pickle_checkpoint_step, tape,
                               HyperparameterSamples({"a__learning_rate": 1}))

    pipeline, actual_data_inputs = pipeline.fit_transform(data_inputs, expected_outputs)

    actual_tape = tape.get_name_tape()
    assert np.array_equal(actual_data_inputs, data_inputs)
    assert actual_tape == ["1", "2", "3"]

    assert os.path.exists(
        os.path.join(tmpdir, 'ResumablePipeline', 'pickle_checkpoint', 'di', '44f9d6dd8b6ccae571ca04525c3eaffa.pickle'))
    assert os.path.exists(
        os.path.join(tmpdir, 'ResumablePipeline', 'pickle_checkpoint', 'di', '898a67b2f5eeae6393ca4b3162ba8e3d.pickle'))
    assert os.path.exists(
        os.path.join(tmpdir, 'ResumablePipeline', 'pickle_checkpoint', 'eo', '44f9d6dd8b6ccae571ca04525c3eaffa.pickle'))
    assert os.path.exists(
        os.path.join(tmpdir, 'ResumablePipeline', 'pickle_checkpoint', 'eo', '898a67b2f5eeae6393ca4b3162ba8e3d.pickle')) 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:22,代码来源:test_pickle_checkpoint_step.py

示例4: test_when_no_hyperparams_and_saved_same_pipeline_should_load_checkpoint_pickle

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_when_no_hyperparams_and_saved_same_pipeline_should_load_checkpoint_pickle(tmpdir: LocalPath):
    # Given
    tape = TapeCallbackFunction()

    # When
    pipeline_save = create_pipeline(
        tmpdir=tmpdir,
        pickle_checkpoint_step=DefaultCheckpoint(),
        tape=TapeCallbackFunction()
    )
    pipeline_save.fit_transform(data_inputs, expected_outputs)

    pipeline_load = create_pipeline(
        tmpdir=tmpdir,
        pickle_checkpoint_step=DefaultCheckpoint(),
        tape=tape
    )
    pipeline_load, actual_data_inputs = pipeline_load.fit_transform(data_inputs, expected_outputs)

    # Then
    actual_tape = tape.get_name_tape()
    assert np.array_equal(actual_data_inputs, data_inputs)
    assert actual_tape == EXPECTED_TAPE_AFTER_CHECKPOINT 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:25,代码来源:test_pickle_checkpoint_step.py

示例5: test_when_hyperparams_and_saved_same_pipeline_should_load_checkpoint_pickle

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_when_hyperparams_and_saved_same_pipeline_should_load_checkpoint_pickle(tmpdir: LocalPath):
    # Given
    tape = TapeCallbackFunction()

    # When
    pipeline_save = create_pipeline(
        tmpdir=tmpdir,
        pickle_checkpoint_step=DefaultCheckpoint(),
        tape=TapeCallbackFunction(),
        hyperparameters=HyperparameterSamples({"a__learning_rate": 1})
    )
    pipeline_save.fit_transform(data_inputs, expected_outputs)

    pipeline_load = create_pipeline(
        tmpdir=tmpdir,
        pickle_checkpoint_step=DefaultCheckpoint(),
        tape=tape,
        hyperparameters=HyperparameterSamples({"a__learning_rate": 1})
    )
    pipeline_load, actual_data_inputs = pipeline_load.fit_transform(data_inputs, expected_outputs)

    # Then
    actual_tape = tape.get_name_tape()
    assert np.array_equal(actual_data_inputs, data_inputs)
    assert actual_tape == EXPECTED_TAPE_AFTER_CHECKPOINT 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:27,代码来源:test_pickle_checkpoint_step.py

示例6: test_pickle_checkpoint_step_should_load_data_container

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_pickle_checkpoint_step_should_load_data_container(tmpdir: LocalPath):
    initial_data_inputs = [1, 2]
    initial_expected_outputs = [2, 3]

    create_pipeline_output_transformer = lambda: ResumablePipeline(
        [
            ('output_transformer_1', MultiplyBy2OutputTransformer()),
            ('pickle_checkpoint', DefaultCheckpoint()),
            ('output_transformer_2', MultiplyBy2OutputTransformer()),
        ], cache_folder=tmpdir)

    create_pipeline_output_transformer().fit_transform(
        data_inputs=initial_data_inputs, expected_outputs=initial_expected_outputs
    )
    transformer = create_pipeline_output_transformer()
    actual_data_container = transformer.handle_transform(
        DataContainer(data_inputs=initial_data_inputs, current_ids=[0, 1], expected_outputs=initial_expected_outputs),
        ExecutionContext(tmpdir)
    )

    assert np.array_equal(actual_data_container.data_inputs, [4, 8])
    assert np.array_equal(actual_data_container.expected_outputs, [8, 12]) 
开发者ID:Neuraxio,项目名称:Neuraxle,代码行数:24,代码来源:test_pickle_checkpoint_step.py

示例7: test_arguments_system_packages

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_arguments_system_packages(tmpdir):
    """Show that we can pass arguments through to virtualenv"""
    tmpdir.chdir()
    requirements('')

    venv_update('venv=', '--system-site-packages', 'venv')

    out, err = run('venv/bin/python', '-c', '''\
import sys
for p in sys.path:
    if p.startswith(sys.real_prefix) and p.endswith("-packages"):
        print(p)
        break
''')
    assert err == ''
    out = out.rstrip('\n')
    assert out and Path(out).isdir() 
开发者ID:Yelp,项目名称:venv-update,代码行数:19,代码来源:simple_test.py

示例8: assert_timestamps

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def assert_timestamps(*reqs):
    firstreq = Path(reqs[0])
    lastreq = Path(reqs[-1])
    args = ['install='] + sum([['-r', req] for req in reqs], [])

    venv_update(*args)

    assert firstreq.mtime() < Path('venv').mtime()

    # garbage, to cause a failure
    lastreq.write('-w wat')

    with pytest.raises(CalledProcessError) as excinfo:
        venv_update(*args)

    assert excinfo.value.returncode == 1
    assert firstreq.mtime() > Path('venv').mtime()

    # blank requirements should succeed
    lastreq.write('')

    venv_update(*args)
    assert firstreq.mtime() < Path('venv').mtime() 
开发者ID:Yelp,项目名称:venv-update,代码行数:25,代码来源:simple_test.py

示例9: test_args_backward

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_args_backward(tmpdir):
    tmpdir.chdir()
    enable_coverage()
    requirements('')

    with pytest.raises(CalledProcessError) as excinfo:
        venv_update('venv=', 'requirements.txt')

    assert excinfo.value.returncode == 3
    out, err = excinfo.value.result
    err = strip_coverage_warnings(err)
    err = strip_pip_warnings(err)
    assert err == ''
    out = uncolor(out)
    assert out.rsplit('\n', 4)[-4:] == [
        '> virtualenv requirements.txt',
        'ERROR: File already exists and is not a directory.',
        'Please provide a different path or delete the file.',
        '',
    ]

    assert Path('requirements.txt').isfile()
    assert Path('requirements.txt').read() == ''
    assert not Path('myvenv').exists() 
开发者ID:Yelp,项目名称:venv-update,代码行数:26,代码来源:simple_test.py

示例10: child_pids

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def child_pids(pid):
    """Return a list of direct child PIDs for the given PID."""
    children = set()
    for p in LocalPath('/proc').listdir():
        try:
            stat = open(p.join('stat').strpath).read()
            m = re.match(r'^\d+ \(.+?\) [a-zA-Z] (\d+) ', stat)
            assert m, stat
            ppid = int(m.group(1))
            if ppid == pid:
                children.add(int(p.basename))
        except OSError:
            # Happens when the process exits after listing it, or between
            # opening stat and reading it.
            pass
    return children 
开发者ID:Yelp,项目名称:dumb-init,代码行数:18,代码来源:__init__.py

示例11: test_safe_join

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_safe_join(tmpdir: LocalPath) -> None:
    directory = tmpdir.realpath()
    tmpdir.join("file.txt").write("something")
    assert safe_join(directory, "file.txt") == Path(directory, "file.txt") 
开发者ID:pgjones,项目名称:quart,代码行数:6,代码来源:test_static.py

示例12: test_safe_join_raises

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_safe_join_raises(paths: List[str], tmpdir: LocalPath) -> None:
    directory = tmpdir.mkdir("safe").realpath()
    tmpdir.mkdir("other")
    tmpdir.mkdir("safes").join("file").write("something")
    with pytest.raises(NotFound):
        safe_join(directory, *paths) 
开发者ID:pgjones,项目名称:quart,代码行数:8,代码来源:test_static.py

示例13: test_send_file_path

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_send_file_path(tmpdir: LocalPath) -> None:
    app = Quart(__name__)
    file_ = tmpdir.join("send.img")
    file_.write("something")
    async with app.app_context():
        response = await send_file(Path(file_.realpath()))
    assert (await response.get_data(raw=True)) == file_.read_binary() 
开发者ID:pgjones,项目名称:quart,代码行数:9,代码来源:test_static.py

示例14: test_send_file_as_attachment

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_send_file_as_attachment(tmpdir: LocalPath) -> None:
    app = Quart(__name__)
    file_ = tmpdir.join("send.img")
    file_.write("something")
    async with app.app_context():
        response = await send_file(Path(file_.realpath()), as_attachment=True)
    assert response.headers["content-disposition"] == "attachment; filename=send.img" 
开发者ID:pgjones,项目名称:quart,代码行数:9,代码来源:test_static.py

示例15: test_send_file_as_attachment_name

# 需要导入模块: from py._path import local [as 别名]
# 或者: from py._path.local import LocalPath [as 别名]
def test_send_file_as_attachment_name(tmpdir: LocalPath) -> None:
    app = Quart(__name__)
    file_ = tmpdir.join("send.img")
    file_.write("something")
    async with app.app_context():
        response = await send_file(
            Path(file_.realpath()), as_attachment=True, attachment_filename="send.html"
        )
    assert response.headers["content-disposition"] == "attachment; filename=send.html" 
开发者ID:pgjones,项目名称:quart,代码行数:11,代码来源:test_static.py


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