tests.test_metadata   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 80
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 9

6 Functions

Rating   Name   Duplication   Size   Complexity  
A album_info() 0 7 1
A metadata() 0 3 1
A test_album_dir() 0 3 1
A tags_from_file_name() 0 8 2
A test_writting_album_metadata() 0 31 3
A test_metadata_dealer_object() 0 2 1
1
"""This module tests writting metadata to audio files . It tests both valid and invalid values for the 'year' (TDRC) field"""
2 1
import os
3 1
from glob import glob
4
5 1
import pytest
6 1
from mutagen.id3 import ID3
7 1
8 1
from music_album_creation.metadata import MetadataDealer as MD
9
from music_album_creation.tracks_parsing import StringParser
10
11 1
12
@pytest.fixture(scope='module')
13 1
def metadata():
14
    return MD()
15 1
16
17 1
@pytest.fixture(scope='module')
18
def test_album_dir():
19
    return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/album_0/')
20 1
21
22 1
@pytest.fixture(scope='module')
23
def album_info():
24
    return {
25
        'artist': ['ratm', 'TPE1'],
26
        'album-artist': ['ratm', 'TPE2'],
27 1
        'album': ['renegades', 'TALB'],
28
        'year': ['2000', 'TDRC'],
29 1
    }
30
31
32
@pytest.fixture(scope='module')
33 1
def tags_from_file_name():
34
    return {
35
        'track_number': {
36
            'tag': 'TRCK',
37
            'parser': lambda x: str(int(x)),
38
        },  # 4.2.1   TRCK    [#TRCK Track number/Position in set]
39 1
        'track_name': {'tag': 'TIT2'},
40
    }  # 4.2.1   TIT2    [#TIT2 Title/songname/content description]
41 1
42 1
43 1
@pytest.mark.parametrize(
44
    "year",
45
    [
46
        ('2000'),
47
        (''),
48 1
        pytest.param('a_year', marks=pytest.mark.xfail),
49
    ],
50
)
51 1
def test_writting_album_metadata(year, test_album_dir, album_info, tags_from_file_name):
52 1
    MD.set_album_metadata(
53
        test_album_dir,
54
        track_number=True,
55
        track_name=True,
56
        artist=album_info['artist'][0],
57
        album_artist=album_info['album-artist'][0],
58
        album=album_info['album'][0],
59
        year=year,
60
    )
61
    for file_path in glob(test_album_dir + '/*'):
62
        c = StringParser().parse_track_number_n_name(os.path.basename(file_path))
63
        audio = ID3(file_path)
64
        # this is true because when trying to set the year metadata with '' the tag s do not change and so remain to the '2000' value set in the first test in line
65
        # assert all([str(audio.get(album_info[k][1]) == album_info[k][0] for k in ['artist', 'album-artist', 'album'])]) and str(audio.get(album_info['year'][1])) == album_info
66
        # for k, v in tags_from_file_name.items():
67
        #     print("TAG SET: {}={}, requested: {}={}".format(v, str(audio.get(v)), k, c[k]))
68
        assert all(
69
            [str(audio.get(album_info[k][1]) == album_info[k][0] for k in album_info.keys())]
70
        ) and all(
71
            [
72
                str(audio.get(data['tag'])) == data.get('parser', lambda x: x)(c[k])
73
                for k, data in tags_from_file_name.items()
74
            ]
75
        )
76
77
78
def test_metadata_dealer_object(metadata):
79
    assert hasattr(metadata, '_filters')
80