Skip to content

Commit

Permalink
Merge 2604edf into b786128
Browse files Browse the repository at this point in the history
  • Loading branch information
fetzerch committed Oct 19, 2018
2 parents b786128 + 2604edf commit 62babbb
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 177 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = .tox/*
60 changes: 53 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
__pycache__
tags
lib

.tox
*.egg-info
# C extensions
*.so

.coverage
# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
AUTHORS
ChangeLog

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
cover/
htmlcov/
.tox/
.coverage
.cache
.pytest_cache/
nosetests.xml
coverage.xml
junit-*.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

sync_music.log
# Sphinx documentation
docs/_build/
23 changes: 10 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
image: python:3.5

cache:
paths:
- .pip
- .tox

before_script:
- apt-get update &&
apt-get install -y lame libmp3lame-dev libmpg123-dev libvorbis-dev
- pip --cache-dir=.pip install tox

flake8:
script:
- tox -e flake8

pylint:
py35:
image: python:3.5
script:
- tox -e pylint
- tox -e py35
coverage: '/\S+\.py\s+(?:\d+\s+){4}(\d+\%)/'

py35:
py36:
image: python:3.6
script:
- apt-get update &&
apt-get install -y lame libmp3lame-dev libmpg123-dev libvorbis-dev
- tox -e py35-cover
coverage: '/TOTAL\s+(?:\d+\s+){4}(\d+\%)/'
- tox -e py36
coverage: '/\S+\.py\s+(?:\d+\s+){4}(\d+\%)/'
19 changes: 9 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
language: python
install: pip install tox coveralls
addons:
apt:
packages:
- lame
- libmp3lame-dev
- libmpg123-dev
- libvorbis-dev
matrix:
fast_finish: true
install: pip install tox
script: tox

jobs:
include:
- python: 3.5
env: TOXENV=flake8
- python: 3.5
env: TOXENV=pylint
- python: 3.5
env: TOXENV=py35-cover
script: tox
after_success: coveralls
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
install: pip install tox coveralls
after_success: coveralls
8 changes: 0 additions & 8 deletions pylintrc.ini

This file was deleted.

2 changes: 1 addition & 1 deletion sync_music/sync_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def load_settings(arguments=None): # pylint: disable=too-many-locals
# Read default settings from config file
if args.config_file is None:
args.config_file = util.makepath('~/.sync_music')
config = configparser.SafeConfigParser()
config = configparser.ConfigParser()
config.read([args.config_file])
try:
defaults = dict(config.items("Defaults"))
Expand Down
34 changes: 18 additions & 16 deletions tests/test_hashdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,31 @@

"""Tests the HashDb implementation."""

from nose.tools import eq_
import os

from sync_music.sync_music import HashDb
import pytest

from . import util
from sync_music.sync_music import HashDb


class TestHashDb:
"""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
@pytest.fixture()
def testfile(tmpdir):
"""Setup test file in temporary directory."""
return os.path.join(str(tmpdir), 'test_hashdb.db')

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

def test_writeerror(self):
"""Test write error."""
Expand All @@ -49,19 +50,20 @@ def test_writeerror(self):
hashdb.store()
hashdb.database = {}
hashdb.load()
eq_(hashdb.database, {})
assert hashdb.database == {}

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

def test_hash(self):
@staticmethod
def test_hash(testfile):
"""Test file hashing."""
with open(self.filename, 'wb') as out_file:
with open(testfile, 'wb') as out_file:
out_file.write(b"TEST")
eq_(HashDb.get_hash(self.filename),
'033bd94b1168d7e4f0d644c3c95e35bf')
assert HashDb.get_hash(testfile) == \
'033bd94b1168d7e4f0d644c3c95e35bf'
73 changes: 41 additions & 32 deletions tests/test_sync_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,40 @@
import os
import shutil

from unittest.mock import patch
from nose.tools import eq_
from nose.tools import raises
from unittest import mock

import pytest

from sync_music.sync_music import SyncMusic
from sync_music.sync_music import load_settings
from sync_music.util import list_all_files

from . import util


class TestSyncMusicSettings:
"""Tests sync_music load_settings function."""

@staticmethod
@raises(SystemExit)
def test_noparams():
"""Tests loading of settings without parameters."""
load_settings('')
with pytest.raises(SystemExit):
load_settings('')

@staticmethod
@raises(SystemExit)
def test_nonexistent():
"""Tests loading of settings with incorrect paths."""
argv = ['--audio-src', '/proc/nonexistingpath',
'--audio-dest', '/proc/nonexistingpath']
load_settings(argv)
with pytest.raises(SystemExit):
load_settings(argv)

@staticmethod
@raises(SystemExit)
def test_forcecopy_with_hacks():
"""Tests loading of settings with force copy and hacks."""
argv = ['--audio-src', '/tmp',
'--audio-dest', '/tmp',
'--mode=copy', '--albumartist-artist-hack']
load_settings(argv)
with pytest.raises(SystemExit):
load_settings(argv)

@staticmethod
def test_configfile():
Expand All @@ -72,23 +70,24 @@ def test_configfile():
os.remove(filename)


class TestSyncMusicFiles(util.TemporaryOutputPathFixture):
class TestSyncMusicFiles():
"""Tests sync_music audio conversion."""

input_path = 'tests/reference_data/regular'
output_path = '/tmp/sync_music'
output_path = None

output_files = [
'stripped_flac.mp3', 'stripped_mp3.mp3', 'stripped_ogg.mp3',
'withtags_flac.mp3', 'withtags_mp3.mp3', 'withtags_ogg.mp3',
'sync_music.db', 'folder.jpg', 'dir/folder.jpg'
]

def __init__(self):
super(TestSyncMusicFiles, self).__init__(self.output_path)
@pytest.fixture(autouse=True)
def init_output_path(self, tmpdir):
"""Setup temporary output directory."""
self.output_path = str(tmpdir)

def _execute_sync_music(self, input_path=input_path,
output_files=None,
def _execute_sync_music(self, input_path=input_path, output_files=None,
arguments=None, jobs=None):
"""Helper method to run sync_music tests."""
if output_files is None:
Expand All @@ -100,12 +99,12 @@ def _execute_sync_music(self, input_path=input_path,
args.jobs = 1 if jobs is None else jobs
sync_music = SyncMusic(args)
sync_music.sync_audio()
eq_(set(list_all_files(self.output_path)), set(output_files))
assert set(list_all_files(self.output_path)) == set(output_files)

@raises(FileNotFoundError)
def test_emptyfolder(self):
"""Test empty input folder."""
self._execute_sync_music(self.output_path, [])
with pytest.raises(FileNotFoundError):
self._execute_sync_music(self.output_path, [])

def test_filenames_utf8(self):
"""Test UTF-8 input file names."""
Expand Down Expand Up @@ -142,7 +141,7 @@ def test_reference_cleanup(self):
def query_no(_):
"""Replacement for sync_music.util.query_yes_no."""
return False
with patch('sync_music.util.query_yes_no', side_effect=query_no):
with mock.patch('sync_music.util.query_yes_no', side_effect=query_no):
self._execute_sync_music(input_path, output_files)

# Delete a file also in output directory (to check double deletion)
Expand All @@ -159,7 +158,7 @@ def query_yes(_):
output_files = [
'stripped_mp3.mp3', 'sync_music.db'
]
with patch('sync_music.util.query_yes_no', side_effect=query_yes):
with mock.patch('sync_music.util.query_yes_no', side_effect=query_yes):
self._execute_sync_music(input_path, output_files)

def test_reference_multiprocessing(self):
Expand Down Expand Up @@ -192,24 +191,34 @@ def test_reference_hacks(self):
'--discnumber-hack', '--tracknumber-hack'
])

def test_reference_exception(self):
def test_reference_ioerror(self, mocker):
"""Test reference folder with mocked IOError."""
mocker.patch('sync_music.transcode.Transcode.execute',
side_effect=IOError('Mocked exception'))
mocker.patch('sync_music.actions.Copy.execute',
side_effect=IOError('Mocked exception'))
self._execute_sync_music(output_files=['sync_music.db'])

def test_reference_exception(self, mocker):
"""Test reference folder with mocked random exception."""
with patch('sync_music.transcode.Transcode.execute',
side_effect=Exception('Mocked exception')):
with patch('sync_music.actions.Copy.execute',
side_effect=IOError('Mocked exception')):
self._execute_sync_music(output_files=['sync_music.db'])
mocker.patch('sync_music.transcode.Transcode.execute',
side_effect=Exception('Mocked exception'))
mocker.patch('sync_music.actions.Copy.execute',
side_effect=Exception('Mocked exception'))
self._execute_sync_music(output_files=['sync_music.db'])


class TestSyncMusicPlaylists(util.TemporaryOutputPathFixture):
class TestSyncMusicPlaylists():
"""Tests sync_music playlist conversion."""

input_path = 'tests/reference_data/regular'
output_path = None
playlist_path = 'tests/reference_data/playlists'
output_path = '/tmp/sync_music'

def __init__(self):
super(TestSyncMusicPlaylists, self).__init__(self.output_path)
@pytest.fixture(autouse=True)
def init_output_path(self, tmpdir):
"""Setup temporary output directory."""
self.output_path = str(tmpdir)

def _execute_sync_music(self, playlist_path=playlist_path):
"""Helper method to run sync_music tests."""
Expand Down

0 comments on commit 62babbb

Please sign in to comment.