本文整理汇总了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)
示例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)
示例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'))
示例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
示例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
示例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])
示例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()
示例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()
示例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()
示例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
示例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")
示例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)
示例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()
示例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"
示例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"