Exemple #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)
Exemple #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"})
Exemple #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()
Exemple #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()
Exemple #5
0
def test_snapshot_reference(tmpdir):
    """Tests snapshot references are loaded."""
    reference_file = tmpdir.join("test.json")
    snapshot = Snapshot("test", data_dir=reference_file.dirname)
    reference_content = "FOO"
    reference_file.write(reference_content)
    assert snapshot.reference == reference_content
Exemple #6
0
def test_snapshot_clean(input, clean_output):
    """Tests the cleanup of snapshot contexts."""
    snapshot = Snapshot("test")
    assert snapshot.clean(input) == clean_output
Exemple #7
0
def test_snapshot_reference_non_existant(tmpdir):
    """Tests snapshots for non-existant references."""
    reference_file = tmpdir.join("non-existant")
    snapshot = Snapshot("non-existant", data_dir=reference_file.dirname)
    assert snapshot.reference is None
Exemple #8
0
def test_snapshot_filepath(tmpdir):
    """Tests file paths fall under `data_dir`."""
    reference_file = tmpdir.join("foo")
    snapshot = Snapshot("foo", data_dir=reference_file.dirname)
    snapshot.filepath == reference_file
Exemple #9
0
def test_snapshot_filepath_out_of_data_dir(tmpdir, bogus_filepath):
    """Tests files cannot fall anywhere but under `data_dir`."""
    reference_file = tmpdir.join("non-existant")
    snapshot = Snapshot(bogus_filepath, data_dir=reference_file.dirname)
    with pytest.raises(ValueError):
        snapshot.filepath