7
7
import pytest
8
8
9
9
import nowplaying .utils # pylint: disable=import-error
10
- import nowplaying .textoutput # pylint: disable=import-error
10
+ import nowplaying .textoutput # pylint: disable=import-error,no-member
11
11
12
12
13
13
@pytest .fixture
@@ -33,7 +33,7 @@ def test_writingmeta(gettemplatehandler): # pylint: disable=redefined-outer-nam
33
33
'title' : 'this is the title' ,
34
34
}
35
35
36
- nowplaying .textoutput .writetxttrack (filename = filename ,
36
+ nowplaying .textoutput .writetxttrack (filename = filename , # pylint: disable=no-member
37
37
templatehandler = gettemplatehandler ,
38
38
metadata = metadata )
39
39
with open (filename ) as tempfn : # pylint: disable=unspecified-encoding
@@ -51,7 +51,7 @@ def test_missingmeta(gettemplatehandler): # pylint: disable=redefined-outer-nam
51
51
52
52
metadata = {}
53
53
54
- nowplaying .textoutput .writetxttrack (filename = filename ,
54
+ nowplaying .textoutput .writetxttrack (filename = filename , # pylint: disable=no-member
55
55
templatehandler = gettemplatehandler ,
56
56
metadata = metadata )
57
57
with open (filename ) as tempfn : # pylint: disable=unspecified-encoding
@@ -71,7 +71,7 @@ def test_missingtemplate(gettemplatehandler): # pylint: disable=redefined-outer
71
71
'title' : 'this is the title' ,
72
72
}
73
73
74
- nowplaying .textoutput .writetxttrack (filename = filename ,
74
+ nowplaying .textoutput .writetxttrack (filename = filename , # pylint: disable=no-member
75
75
templatehandler = gettemplatehandler ,
76
76
metadata = metadata )
77
77
with open (filename ) as tempfn : # pylint: disable=unspecified-encoding
@@ -90,7 +90,7 @@ def test_missingfilename(gettemplatehandler): # pylint: disable=redefined-outer
90
90
'title' : 'this is the title' ,
91
91
}
92
92
93
- nowplaying .textoutput .writetxttrack (filename = filename ,
93
+ nowplaying .textoutput .writetxttrack (filename = filename , # pylint: disable=no-member
94
94
templatehandler = gettemplatehandler ,
95
95
metadata = metadata )
96
96
with open (filename ) as tempfn : # pylint: disable=unspecified-encoding
@@ -103,7 +103,7 @@ def test_cleartemplate(): # pylint: disable=redefined-outer-name
103
103
''' try writing a text '''
104
104
with tempfile .TemporaryDirectory () as newpath :
105
105
filename = os .path .join (newpath , 'test.txt' )
106
- nowplaying .textoutput .writetxttrack (filename = filename , clear = True )
106
+ nowplaying .textoutput .writetxttrack (filename = filename , clear = True ) # pylint: disable=no-member
107
107
with open (filename ) as tempfn : # pylint: disable=unspecified-encoding
108
108
content = tempfn .readlines ()
109
109
@@ -114,8 +114,47 @@ def test_justafile(): # pylint: disable=redefined-outer-name
114
114
''' try writing a text '''
115
115
with tempfile .TemporaryDirectory () as newpath :
116
116
filename = os .path .join (newpath , 'test.txt' )
117
- nowplaying .textoutput .writetxttrack (filename = filename )
117
+ nowplaying .textoutput .writetxttrack (filename = filename ) # pylint: disable=no-member
118
118
with open (filename ) as tempfn : # pylint: disable=unspecified-encoding
119
119
content = tempfn .readlines ()
120
120
121
121
assert content [0 ] == '{{ artist }} - {{ title }}'
122
+
123
+
124
+ @pytest .mark .templatesettings (template = 'tracktest.txt' )
125
+ @pytest .mark .parametrize (
126
+ "track_value,disc_value,expected_track,expected_disc" ,
127
+ [
128
+ ('0' , '0' , True , True ), # Track 0 and disc 0 should show
129
+ ('1' , '1' , True , True ), # Track 1 and disc 1 should show
130
+ ('' , '' , False , False ), # Empty strings should not show
131
+ (None , None , False , False ), # None values should not show
132
+ ])
133
+ def test_track_disc_handling ( # pylint: disable=redefined-outer-name
134
+ gettemplatehandler , track_value , disc_value , expected_track ,
135
+ expected_disc ):
136
+ ''' test track and disc number handling with various values '''
137
+ with tempfile .TemporaryDirectory () as newpath :
138
+ filename = os .path .join (newpath , 'test.txt' )
139
+
140
+ metadata = {}
141
+ if track_value is not None :
142
+ metadata ['track' ] = track_value
143
+ if disc_value is not None :
144
+ metadata ['disc' ] = disc_value
145
+
146
+ nowplaying .textoutput .writetxttrack (filename = filename , # pylint: disable=no-member
147
+ templatehandler = gettemplatehandler ,
148
+ metadata = metadata )
149
+ with open (filename ) as tempfn : # pylint: disable=unspecified-encoding
150
+ content = tempfn .read ()
151
+
152
+ if expected_track :
153
+ assert f'Track: { track_value } ' in content
154
+ else :
155
+ assert 'Track:' not in content
156
+
157
+ if expected_disc :
158
+ assert f'Disc: { disc_value } ' in content
159
+ else :
160
+ assert 'Disc:' not in content
0 commit comments