def test_to_lockfile(dvc):
    stage = create_stage(PipelineStage, dvc, deps=["input"], **kwargs)
    stage.deps[0].info = {"md5": "md-five"}
    entry = to_lockfile(stage)
    assert len(entry) == 1
    _Schema(LOCKFILE_SCHEMA)(entry)
    assert entry == {
        "something":
        OrderedDict([
            ("cmd", "command"),
            ("deps", [{
                "path": "input",
                "md5": "md-five"
            }]),
        ])
    }
from collections import OrderedDict

import pytest
from voluptuous import Schema as _Schema

from dvc.dvcfile import PIPELINE_FILE
from dvc.schema import LOCK_FILE_STAGE_SCHEMA, LOCKFILE_SCHEMA
from dvc.stage import PipelineStage, create_stage
from dvc.stage.serialize import DEFAULT_PARAMS_FILE, to_lockfile
from dvc.stage.serialize import (
    to_single_stage_lockfile as _to_single_stage_lockfile, )
from dvc.stage.utils import split_params_deps

kwargs = {"name": "something", "cmd": "command", "path": PIPELINE_FILE}
Schema = _Schema(LOCK_FILE_STAGE_SCHEMA)


def to_single_stage_lockfile(stage):
    """Validate schema on each serialization."""
    e = _to_single_stage_lockfile(stage)
    assert Schema(e)
    return e


def test_lock(dvc):
    stage = create_stage(PipelineStage, dvc, **kwargs)
    assert to_single_stage_lockfile(stage) == {"cmd": "command"}


def test_lock_deps(dvc):
    stage = create_stage(PipelineStage, dvc, deps=["input"], **kwargs)
Example #3
0
import os

import pytest
from voluptuous import Schema as _Schema

from dvc import output
from dvc.dvcfile import PIPELINE_FILE
from dvc.schema import SINGLE_PIPELINE_STAGE_SCHEMA
from dvc.stage import PipelineStage, create_stage
from dvc.stage.serialize import to_pipeline_file as _to_pipeline_file

kwargs = {"name": "something", "cmd": "command", "path": PIPELINE_FILE}
Schema = _Schema(SINGLE_PIPELINE_STAGE_SCHEMA)


def to_pipeline_file(stage):
    """Validate schema on each serialization."""
    e = _to_pipeline_file(stage)
    assert len(Schema(e)) == 1
    return e


def test_cmd(dvc):
    stage = create_stage(PipelineStage, dvc, **kwargs)
    entry = to_pipeline_file(stage)
    assert entry == {"something": {"cmd": "command"}}


def test_wdir(dvc):
    stage = create_stage(PipelineStage, dvc, **kwargs)
    assert stage.PARAM_WDIR not in to_pipeline_file(stage)["something"]