Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add tests #4

Merged
merged 1 commit into from
Oct 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ lib

.tox
*.egg-info

.coverage
cover/
17 changes: 17 additions & 0 deletions sync_music.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@

tox -e flake8 | tee $WORKSPACE/build/flake8.log
tox -e pylint | tee $WORKSPACE/build/pylint.log
tox -e py34-cover -- \
--with-xunit --xunit-file=$WORKSPACE/build/nosetests.xml \
--cover-xml --cover-xml-file=$WORKSPACE/build/coverage.xml \
| tee $WORKSPACE/build/py34-cover.log


# ----- Publisher -------------------------------------------------------------
Expand All @@ -90,6 +94,19 @@
total-thresholds:
unstable:
total-all: 0
- junit:
results: build/nosetests.xml
test-stability: true
- cobertura:
report-file: build/coverage.xml
fail-no-reports: true
targets:
- files:
failing: 10000000
- line:
failing: 10000000
- conditional:
failing: 10000000


# ----- Parameter -------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion sync_music/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ def get_out_filename(cls, _):
return None

@classmethod
def execute(cls, in_filepath, out_filepath):
def execute(cls, in_filepath, out_filepath): # pragma: no cover
""" Executes action """
pass
2 changes: 1 addition & 1 deletion sync_music/sync_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def load_settings(arguments=None):
return settings


def main():
def main(): # pragma: no cover
""" sync_music - Sync music library to external device """
args = load_settings()
sync_music = SyncMusic(args)
Expand Down
2 changes: 1 addition & 1 deletion sync_music/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def correct_path_fat32(filename):
return re.sub(r'[\\|:|*|?|"|<|>|\|]', '_', filename)


def query_yes_no(question):
def query_yes_no(question): # pragma: no cover
""" Ask a yes/no question, yes being the default """
while 1:
sys.stdout.write(question + ' [Y/n]: ')
Expand Down
Empty file added tests/__init__.py
Empty file.
Binary file not shown.
Binary file added tests/reference_data/audiofiles/folder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/reference_data/audiofiles/stripped.aiff
Binary file not shown.
Binary file added tests/reference_data/audiofiles/stripped.flac
Binary file not shown.
Binary file added tests/reference_data/audiofiles/stripped.mp3
Binary file not shown.
Binary file added tests/reference_data/audiofiles/stripped.ogg
Binary file not shown.
Binary file added tests/reference_data/audiofiles/withalltags.flac
Binary file not shown.
Binary file added tests/reference_data/audiofiles/withalltags.mp3
Binary file not shown.
Binary file added tests/reference_data/audiofiles/withalltags.ogg
Binary file not shown.
Binary file added tests/reference_data/audiofiles/withtags.aiff
Binary file not shown.
Binary file added tests/reference_data/audiofiles/withtags.flac
Binary file not shown.
Binary file added tests/reference_data/audiofiles/withtags.mp3
Binary file not shown.
Binary file added tests/reference_data/audiofiles/withtags.ogg
Binary file not shown.
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/A_<_A.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/B_>_B.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/C_:_C.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/D_"_D.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/E_\_E.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/F_|_F.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/G_?_G.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_fat32/H_*_H.mp3
1 change: 1 addition & 0 deletions tests/reference_data/filenames_utf8/test_äöüß.mp3
Empty file.
8 changes: 8 additions & 0 deletions tests/reference_data/playlists/normal.m3u
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#EXTM3U
tests/reference_data/regular/stripped_flac.flac
tests/reference_data/regular/stripped_mp3.mp3
tests/reference_data/regular/stripped_ogg.ogg
tests/reference_data/regular/withtags_flac.flac
tests/reference_data/regular/withtags_mp3.mp3
tests/reference_data/regular/withtags_ogg.ogg
tests/reference_data/regular/nonexistentfile.mp3
1 change: 1 addition & 0 deletions tests/reference_data/regular/folder.jpg
Empty file.
1 change: 1 addition & 0 deletions tests/reference_data/regular/stripped_flac.flac
1 change: 1 addition & 0 deletions tests/reference_data/regular/stripped_mp3.mp3
1 change: 1 addition & 0 deletions tests/reference_data/regular/stripped_ogg.ogg
1 change: 1 addition & 0 deletions tests/reference_data/regular/withtags_flac.flac
1 change: 1 addition & 0 deletions tests/reference_data/regular/withtags_mp3.mp3
1 change: 1 addition & 0 deletions tests/reference_data/regular/withtags_ogg.ogg
1 change: 1 addition & 0 deletions tests/reference_data/regular_cleanup/stripped_mp3.mp3
67 changes: 67 additions & 0 deletions tests/test_hashdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# music_sync - Sync music library to external device
# Copyright (C) 2013-2015 Christian Fetzer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

""" Tests the HashDb implementation """

from nose.tools import eq_

from sync_music.sync_music import HashDb

from . import util


class TestHashDb(object):
""" Tests the HashDb implementation """
# Format: { in_filename : (out_filename, hash) }
data = {'test1': ('test2', 'test3'),
'test_utf8': ('test_äöüß', 'test_ÄÖÜß')}
filename = 'test_hashdb.db'

def teardown(self):
""" Remove test file after each testcase """
util.silentremove(self.filename)

@staticmethod
def test_nonexistent():
""" Test non existent file """
hashdb = HashDb('/nonexistent')
hashdb.load()
eq_(hashdb.database, {})

def test_writeerror(self):
""" Test write error """
hashdb = HashDb('/nonexistent')
hashdb.database = self.data
hashdb.store()
hashdb.database = {}
hashdb.load()
eq_(hashdb.database, {})

def test_storeandload(self):
""" Test normal operation """
hashdb = HashDb('test_hashdb.db')
hashdb.database = self.data
hashdb.store()
hashdb.load()
eq_(hashdb.database, self.data)

def test_hash(self):
""" Test file hashing """
with open(self.filename, 'wb') as out_file:
out_file.write(b"TEST")
eq_(HashDb.get_hash(self.filename),
'033bd94b1168d7e4f0d644c3c95e35bf')
Loading