File: test_context_manager.py

package info (click to toggle)
pytaglib 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,136 kB
  • sloc: python: 429; makefile: 7
file content (23 lines) | stat: -rw-r--r-- 654 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import taglib


def test_exit_closes_file(test_file):
    with test_file("r2.mp3") as f:
        assert not f.is_closed
    assert f.is_closed


def test_exit_saves_if_requested(test_data):
    file = test_data("r2.mp3")
    with taglib.File(file, save_on_exit=True) as f:
        f.tags["ARTIST"] = ["overridden"]
    with taglib.File(file) as f:
        assert f.tags["ARTIST"] == ["overridden"]


def test_exit_does_not_save_if_not_requested(test_data):
    file = test_data("r2.mp3")
    with taglib.File(file, save_on_exit=False) as f:
        f.tags["ARTIST"] = ["overridden"]
    with taglib.File(file) as f:
        assert "ARTIST" not in f.tags