From 35a8d69c4f46c4c8d92f115963ee3b27b147c657 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Tue, 23 Jul 2019 12:16:07 +0300 Subject: [PATCH] dvc: ignore Stage.meta in md5 calculations Meta change surely should not trigger a repro run. Closes #2209. --- dvc/stage.py | 6 ++-- tests/unit/test_stage.py | 72 ++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/dvc/stage.py b/dvc/stage.py index 8ac073c8c..e93d5ab92 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -657,9 +657,9 @@ class Stage(object): d = self.dumpd() - # NOTE: removing md5 manually in order to not affect md5s in deps/outs - if self.PARAM_MD5 in d.keys(): - del d[self.PARAM_MD5] + # Remove md5 and meta, these should not affect stage md5 + d.pop(self.PARAM_MD5, None) + d.pop(self.PARAM_META, None) # Ignore the wdir default value. In this case DVC-file w/o # wdir has the same md5 as a file with the default value specified. diff --git a/tests/unit/test_stage.py b/tests/unit/test_stage.py index c39a7f567..a477059a8 100644 --- a/tests/unit/test_stage.py +++ b/tests/unit/test_stage.py @@ -7,51 +7,43 @@ import pytest from unittest import TestCase -class TestStageChecksum(TestCase): - def test(self): - stage = Stage(None, "path") - outs = [{"path": "a", "md5": "123456789"}] - deps = [{"path": "b", "md5": "987654321"}] - d = {"md5": "123456", "cmd": "mycmd", "outs": outs, "deps": deps} +TEST_STAGE_DICT = { + "md5": "123456", + "cmd": "mycmd", + "outs": [{"path": "a", "md5": "123456789"}], + "deps": [{"path": "b", "md5": "987654321"}], +} - with mock.patch.object(stage, "dumpd", return_value=d): - self.assertEqual( - stage._compute_md5(), "e9521a22111493406ea64a88cda63e0b" - ) - def test_wdir_default_ignored(self): - stage = Stage(None, "path") - outs = [{"path": "a", "md5": "123456789"}] - deps = [{"path": "b", "md5": "987654321"}] - d = { - "md5": "123456", - "cmd": "mycmd", - "outs": outs, - "deps": deps, - "wdir": ".", - } +def test_stage_checksum(): + stage = Stage(None, "path") - with mock.patch.object(stage, "dumpd", return_value=d): - self.assertEqual( - stage._compute_md5(), "e9521a22111493406ea64a88cda63e0b" - ) + with mock.patch.object(stage, "dumpd", return_value=TEST_STAGE_DICT): + assert stage._compute_md5() == "e9521a22111493406ea64a88cda63e0b" - def test_wdir_non_default_is_not_ignored(self): - stage = Stage(None, "path") - outs = [{"path": "a", "md5": "123456789"}] - deps = [{"path": "b", "md5": "987654321"}] - d = { - "md5": "123456", - "cmd": "mycmd", - "outs": outs, - "deps": deps, - "wdir": "..", - } - with mock.patch.object(stage, "dumpd", return_value=d): - self.assertEqual( - stage._compute_md5(), "2ceba15e87f6848aa756502c1e6d24e9" - ) +def test_wdir_default_ignored(): + stage = Stage(None, "path") + d = dict(TEST_STAGE_DICT, wdir=".") + + with mock.patch.object(stage, "dumpd", return_value=d): + assert stage._compute_md5() == "e9521a22111493406ea64a88cda63e0b" + + +def test_wdir_non_default_is_not_ignored(): + stage = Stage(None, "path") + d = dict(TEST_STAGE_DICT, wdir="..") + + with mock.patch.object(stage, "dumpd", return_value=d): + assert stage._compute_md5() == "2ceba15e87f6848aa756502c1e6d24e9" + + +def test_meta_ignored(): + stage = Stage(None, "path") + d = dict(TEST_STAGE_DICT, meta={"author": "Suor"}) + + with mock.patch.object(stage, "dumpd", return_value=d): + assert stage._compute_md5() == "e9521a22111493406ea64a88cda63e0b" class TestPathConversion(TestCase):