Ejemplo n.º 1
0
def test_snapshot_assert_matches(tmpdir):
    """Tests assertion matching."""
    reference_file = tmpdir.join("test.json")
    snapshot = Snapshot("test", data_dir=reference_file.dirname)
    reference_content = "FOO"
    reference_file.write(snapshot.serialize(reference_content))
    snapshot.assert_matches(reference_content)
Ejemplo n.º 2
0
def test_snapshot_assert_matches_error(tmpdir):
    """Tests assertion errors out if the reference does not exist."""
    reference_file = tmpdir.join("test.json")
    snapshot = Snapshot("test", data_dir=reference_file.dirname)
    assert snapshot.reference is None
    with pytest.raises(AssertionError):
        snapshot.assert_matches({"foo": "bar"})
Ejemplo n.º 3
0
def test_snapshot_assert_matches_generate_subdirs_existing(tmpdir):
    """Tests the snapshot is generated also with existing subdirectories."""
    reference_file = tmpdir.join("subdir")
    snapshot = Snapshot("subdir/test", data_dir=reference_file.dirname, generate=True)
    assert snapshot.reference is None
    # The assertion function reported nothing
    assert snapshot.assert_matches({}) is None
    # But the reference dir + file should now be created
    assert reference_file.join("test.json").exists()
Ejemplo n.º 4
0
def test_snapshot_assert_matches_generate(tmpdir):
    """Tests the snapshot is generated if instructed to do so."""
    reference_file = tmpdir.join("test.json")
    snapshot = Snapshot("test", data_dir=reference_file.dirname, generate=True)
    assert snapshot.reference is None
    # The assertion function reported nothing
    assert snapshot.assert_matches({}) is None
    # But the reference file should now be created
    assert reference_file.exists()