Passed
Push — master ( 9ddb09...7fc5b5 )
by Jaisen
01:14
created

elodie.tests.media.video_test   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 200
Duplicated Lines 52 %

Importance

Changes 0
Metric Value
eloc 127
dl 104
loc 200
rs 10
c 0
b 0
f 0
wmc 16

16 Functions

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