| 328 | |
| 329 | |
| 330 | def test_commit_multiple_files(tmp_dir, dvc, mocker): |
| 331 | tmp_dir.gen({"foo": "foo", "bar": "bar"}) |
| 332 | stages = dvc.add(["foo", "bar"], no_commit=True) |
| 333 | test1_stage = dvc.stage.add(name="test", cmd="echo test", deps=["foo"]) |
| 334 | test2_stage = dvc.stage.add(name="test2", cmd="echo test2", deps=["foo"]) |
| 335 | |
| 336 | subdir = tmp_dir / "subdir" |
| 337 | subdir.mkdir() |
| 338 | with subdir.chdir(): |
| 339 | bar_relpath = os.path.relpath(tmp_dir / "bar", subdir) |
| 340 | test3_stage = dvc.stage.add(name="test3", cmd="echo test3", deps=[bar_relpath]) |
| 341 | |
| 342 | pointerfile_spy = mocker.spy(SingleStageFile, "dump_stages") |
| 343 | projectfile_spy = mocker.spy(ProjectFile, "dump_stages") |
| 344 | lockfile_spy = mocker.spy(Lockfile, "dump_stages") |
| 345 | |
| 346 | assert set(dvc.commit(force=True)) == { |
| 347 | *stages, |
| 348 | test1_stage, |
| 349 | test2_stage, |
| 350 | test3_stage, |
| 351 | } |
| 352 | pointerfile_spy.assert_has_calls( |
| 353 | [ |
| 354 | mocker.call(stages[0].dvcfile, [stages[0]], update_pipeline=False), |
| 355 | mocker.call(stages[1].dvcfile, [stages[1]], update_pipeline=False), |
| 356 | ], |
| 357 | any_order=True, |
| 358 | ) |
| 359 | projectfile_spy.assert_has_calls( |
| 360 | [ |
| 361 | mocker.call( |
| 362 | test1_stage.dvcfile, [test1_stage, test2_stage], update_pipeline=False |
| 363 | ), |
| 364 | mocker.call(test3_stage.dvcfile, [test3_stage], update_pipeline=False), |
| 365 | ], |
| 366 | any_order=True, |
| 367 | ) |
| 368 | lockfile_spy.assert_has_calls( |
| 369 | [ |
| 370 | mocker.call(test1_stage.dvcfile._lockfile, [test1_stage, test2_stage]), |
| 371 | mocker.call(test3_stage.dvcfile._lockfile, [test3_stage]), |
| 372 | ], |
| 373 | any_order=True, |
| 374 | ) |
| 375 | assert dvc.status() == {} |