Passed
Push — master ( 9e03c4...3276cc )
by Jaisen
02:00
created

elodie.tests.media.audio_test   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 197
Duplicated Lines 54.82 %

Importance

Changes 0
Metric Value
eloc 123
dl 108
loc 197
rs 10
c 0
b 0
f 0
wmc 15

15 Functions

Rating   Name   Duplication   Size   Complexity  
A test_set_title_non_ascii() 20 20 1
A test_get_camera_model() 0 5 1
A test_get_camera_make() 0 5 1
A test_is_valid() 0 4 1
A test_audio_extensions() 0 9 1
A test_set_title() 19 19 1
A test_is_not_valid() 0 4 1
A test_get_exiftool_attributes() 0 6 1
A test_get_coordinate_longitude() 0 5 1
A test_get_coordinate_latitude() 0 5 1
A test_get_date_taken() 0 5 1
A test_set_location_minus() 25 25 1
A test_set_date_taken() 19 19 1
A test_get_coordinate() 0 5 1
A test_set_location() 25 25 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# -*- coding: utf-8
2
# Project imports
3
from __future__ import print_function
4
import os
5
import sys
6
7
import shutil
8
import tempfile
9
import time
10
import datetime
11
12
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))))
13
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
14
15
import helper
16
from elodie.media.media import Media
17
from elodie.media.video import Video
18
from elodie.media.audio import Audio
19
20
os.environ['TZ'] = 'GMT'
21
22
def test_audio_extensions():
23
    audio = Audio()
24
    extensions = audio.extensions
25
26
    assert 'm4a' in extensions
27
28
    valid_extensions = Audio.get_valid_extensions()
29
30
    assert extensions == valid_extensions, valid_extensions
31
32
def test_get_coordinate():
33
    audio = Audio(helper.get_file('audio.m4a'))
34
    coordinate = audio.get_coordinate()
35
36
    assert helper.isclose(coordinate, 29.758938), coordinate
37
38
def test_get_camera_make():
39
    audio = Audio(helper.get_file('audio.m4a'))
40
    coordinate = audio.get_camera_make()
41
42
    assert coordinate is None, coordinate
43
44
def test_get_camera_model():
45
    audio = Audio(helper.get_file('audio.m4a'))
46
    coordinate = audio.get_camera_model()
47
48
    assert coordinate is None, coordinate
49
50
def test_get_coordinate_latitude():
51
    audio = Audio(helper.get_file('audio.m4a'))
52
    coordinate = audio.get_coordinate('latitude')
53
54
    assert helper.isclose(coordinate, 29.758938), coordinate
55
56
def test_get_coordinate_longitude():
57
    audio = Audio(helper.get_file('audio.m4a'))
58
    coordinate = audio.get_coordinate('longitude')
59
60
    assert helper.isclose(coordinate, -95.3677), coordinate
61
62
def test_get_date_taken():
63
    audio = Audio(helper.get_file('audio.m4a'))
64
    date_taken = audio.get_date_taken()
65
66
    assert date_taken == (2016, 1, 4, 5, 28, 15, 0, 4, 0), date_taken
67
68
def test_get_exiftool_attributes():
69
    audio = Video(helper.get_file('audio.m4a'))
70
    exif = audio.get_exiftool_attributes()
71
72
    assert exif is not None, exif
73
    assert exif is not False, exif
74
75
def test_is_valid():
76
    audio = Audio(helper.get_file('audio.m4a'))
77
78
    assert audio.is_valid()
79
80
def test_is_not_valid():
81
    audio = Audio(helper.get_file('text.txt'))
82
83
    assert not audio.is_valid()
84
85 View Code Duplication
def test_set_date_taken():
0 ignored issues
show
Duplication introduced by Jaisen Mathai
This code seems to be duplicated in your project.
Loading history...
86
    temporary_folder, folder = helper.create_working_folder()
87
88
    origin = '%s/audio.m4a' % folder
89
    shutil.copyfile(helper.get_file('audio.m4a'), origin)
90
91
    audio = Audio(origin)
92
    status = audio.set_date_taken(datetime.datetime(2013, 9, 30, 7, 6, 5))
93
94
    assert status == True, status
95
96
    audio_new = Audio(origin)
97
    metadata = audio_new.get_metadata()
98
99
    date_taken = metadata['date_taken']
100
101
    shutil.rmtree(folder)
102
103
    assert date_taken == (2013, 9, 30, 7, 6, 5, 0, 273, 0), metadata['date_taken']
104
105 View Code Duplication
def test_set_location():
0 ignored issues
show
Duplication introduced by Jaisen Mathai
This code seems to be duplicated in your project.
Loading history...
106
    temporary_folder, folder = helper.create_working_folder()
107
108
    origin = '%s/audio.m4a' % folder
109
    shutil.copyfile(helper.get_file('audio.m4a'), origin)
110
111
    audio = Audio(origin)
112
    origin_metadata = audio.get_metadata()
113
114
    # Verify that original audio has different location info that what we
115
    #   will be setting and checking
116
    assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude']
117
    assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude']
118
119
    status = audio.set_location(11.1111111111, 99.9999999999)
120
121
    assert status == True, status
122
123
    audio_new = Audio(origin)
124
    metadata = audio_new.get_metadata()
125
126
    shutil.rmtree(folder)
127
128
    assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
129
    assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
130
131 View Code Duplication
def test_set_location_minus():
0 ignored issues
show
Duplication introduced by Jaisen Mathai
This code seems to be duplicated in your project.
Loading history...
132
    temporary_folder, folder = helper.create_working_folder()
133
134
    origin = '%s/audio.m4a' % folder
135
    shutil.copyfile(helper.get_file('audio.m4a'), origin)
136
137
    audio = Audio(origin)
138
    origin_metadata = audio.get_metadata()
139
140
    # Verify that original audio has different location info that what we
141
    #   will be setting and checking
142
    assert not helper.isclose(origin_metadata['latitude'], 11.111111), origin_metadata['latitude']
143
    assert not helper.isclose(origin_metadata['longitude'], 99.999999), origin_metadata['longitude']
144
145
    status = audio.set_location(-11.111111, -99.999999)
146
147
    assert status == True, status
148
149
    audio_new = Audio(origin)
150
    metadata = audio_new.get_metadata()
151
152
    shutil.rmtree(folder)
153
154
    assert helper.isclose(metadata['latitude'], -11.111111), metadata['latitude']
155
    assert helper.isclose(metadata['longitude'], -99.999999), metadata['longitude']
156
157 View Code Duplication
def test_set_title():
0 ignored issues
show
Duplication introduced by Jaisen Mathai
This code seems to be duplicated in your project.
Loading history...
158
    temporary_folder, folder = helper.create_working_folder()
159
160
    origin = '%s/audio.m4a' % folder
161
    shutil.copyfile(helper.get_file('audio.m4a'), origin)
162
163
    audio = Audio(origin)
164
    origin_metadata = audio.get_metadata()
165
166
    status = audio.set_title('my audio title')
167
168
    assert status == True, status
169
170
    audio_new = Audio(origin)
171
    metadata = audio_new.get_metadata()
172
173
    shutil.rmtree(folder)
174
175
    assert metadata['title'] == 'my audio title', metadata['title']
176
177 View Code Duplication
def test_set_title_non_ascii():
0 ignored issues
show
Duplication introduced by Jaisen Mathai
This code seems to be duplicated in your project.
Loading history...
178
    temporary_folder, folder = helper.create_working_folder()
179
180
    origin = '%s/audio.m4a' % folder
181
    shutil.copyfile(helper.get_file('audio.m4a'), origin)
182
183
    audio = Audio(origin)
184
    origin_metadata = audio.get_metadata()
185
186
    unicode_title = u'形声字 / 形聲字'
187
    status = audio.set_title(unicode_title)
188
189
    assert status == True, status
190
191
    audio_new = Audio(origin)
192
    metadata = audio_new.get_metadata()
193
194
    shutil.rmtree(folder)
195
196
    assert metadata['title'] == unicode_title, metadata['title']
197