Skip to content

Commit

Permalink
Merge pull request #199 from bsravanin/master
Browse files Browse the repository at this point in the history
Adopting pytest
  • Loading branch information
wackou committed Apr 27, 2015
2 parents 1fd7c59 + d1dff83 commit f637f05
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 267 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Expand Up @@ -7,6 +7,7 @@ nose # TODO: still required?
mock # TODO: still required?
# Test dependencies
PyYAML
Pygments
# Dependency links
# see https://caremad.io/blog/setup-vs-requirement/
-e .
1 change: 1 addition & 0 deletions dodo.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import os
import sys
import re
Expand Down
40 changes: 0 additions & 40 deletions guessit/test/__main__.py

This file was deleted.

3 changes: 1 addition & 2 deletions guessit/test/guessittest.py
Expand Up @@ -183,5 +183,4 @@ def checkFields(self, groundTruth, guess_func, remove_type=True,
for additional_property in additional_properties:
log.warning("ADDITIONAL: " + additional_property)

self.assertTrue(correct == total,
msg='Correct: %d < Total: %d' % (correct, total))
assert correct == total, 'Correct: %d < Total: %d' % (correct, total)
24 changes: 10 additions & 14 deletions guessit/test/test_api.py
Expand Up @@ -32,23 +32,19 @@ def test_api(self):
episode_info = guessit.guess_episode_info(movie_path)
file_info = guessit.guess_file_info(movie_path)

self.assertEqual(guessit.guess_file_info(movie_path, type='movie'), movie_info)
self.assertEqual(guessit.guess_file_info(movie_path, type='video'), video_info)
self.assertEqual(guessit.guess_file_info(movie_path, type='episode'), episode_info)
assert guessit.guess_file_info(movie_path, type='movie') == movie_info
assert guessit.guess_file_info(movie_path, type='video') == video_info
assert guessit.guess_file_info(movie_path, type='episode') == episode_info

self.assertEqual(guessit.guess_file_info(movie_path, options={'type': 'movie'}), movie_info)
self.assertEqual(guessit.guess_file_info(movie_path, options={'type': 'video'}), video_info)
self.assertEqual(guessit.guess_file_info(movie_path, options={'type': 'episode'}), episode_info)
assert guessit.guess_file_info(movie_path, options={'type': 'movie'}) == movie_info
assert guessit.guess_file_info(movie_path, options={'type': 'video'}) == video_info
assert guessit.guess_file_info(movie_path, options={'type': 'episode'}) == episode_info

self.assertEqual(guessit.guess_file_info(movie_path, options={'type': 'episode'}, type='movie'), episode_info) # kwargs priority other options
# kwargs priority other options
assert guessit.guess_file_info(movie_path, options={'type': 'episode'}, type='movie') == episode_info

movie_path_name_only = 'Movies/Dark City (1998)/Dark.City.(1998).DC.BDRip.720p.DTS.X264-CHD'
file_info_name_only = guessit.guess_file_info(movie_path_name_only, options={"name_only": True})

self.assertFalse('container' in file_info_name_only)
self.assertTrue('container' in file_info)

suite = allTests(TestApi)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
assert 'container' not in file_info_name_only
assert 'container' in file_info
12 changes: 3 additions & 9 deletions guessit/test/test_autodetect.py
Expand Up @@ -26,20 +26,14 @@
class TestAutoDetect(TestGuessit):
def testEmpty(self):
result = guessit.guess_file_info('')
self.assertEqual(result, {})
assert result == {}

result = guessit.guess_file_info('___-__')
self.assertEqual(result, {})
assert result == {}

result = guessit.guess_file_info('__-.avc')
self.assertEqual(result, {'type': 'unknown', 'extension': 'avc'})
assert result == {'type': 'unknown', 'extension': 'avc'}

def testAutoDetect(self):
self.checkMinimumFieldsCorrect(filename='autodetect.yaml',
remove_type=False)


suite = allTests(TestAutoDetect)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
6 changes: 0 additions & 6 deletions guessit/test/test_autodetect_all.py
Expand Up @@ -38,9 +38,3 @@ def testAutoMatcherMovies(self):
def testAutoMatcherEpisodes(self):
self.checkMinimumFieldsCorrect(filename='episodes.yaml',
exclude_files=IGNORE_EPISODES)


suite = allTests(TestAutoDetectAll)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
45 changes: 0 additions & 45 deletions guessit/test/test_doctests.py

This file was deleted.

6 changes: 0 additions & 6 deletions guessit/test/test_episode.py
Expand Up @@ -27,9 +27,3 @@ class TestEpisode(TestGuessit):
def testEpisodes(self):
self.checkMinimumFieldsCorrect(filetype='episode',
filename='episodes.yaml')


suite = allTests(TestEpisode)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
9 changes: 2 additions & 7 deletions guessit/test/test_hashes.py
Expand Up @@ -37,10 +37,5 @@ def test_hashes(self):
for hash_type, filename, expected_value in hashes:
guess = guess_file_info(file_in_same_dir(__file__, filename), hash_type)
computed_value = guess.get(hash_type)
self.assertEqual(expected_value, guess.get(hash_type), "Invalid %s for %s: %s != %s" % (hash_type, filename, computed_value, expected_value))


suite = allTests(TestHashes)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
assert expected_value == guess.get(hash_type), \
"Invalid %s for %s: %s != %s" % (hash_type, filename, computed_value, expected_value)
19 changes: 5 additions & 14 deletions guessit/test/test_language.py
Expand Up @@ -29,8 +29,7 @@ class TestLanguage(TestGuessit):

def check_languages(self, languages):
for lang1, lang2 in languages.items():
self.assertEqual(Language.fromguessit(lang1),
Language.fromguessit(lang2))
assert Language.fromguessit(lang1) == Language.fromguessit(lang2)

def test_addic7ed(self):
languages = {'English': 'en',
Expand Down Expand Up @@ -91,15 +90,15 @@ def test_opensubtitles(self):
if int(upload_enabled) and int(web_enabled):
# check that we recognize the opensubtitles language code correctly
# and that we are able to output this code from a language
self.assertEqual(idlang, Language.fromguessit(idlang).opensubtitles)
assert idlang == Language.fromguessit(idlang).opensubtitles
if alpha2:
# check we recognize the opensubtitles 2-letter code correctly
self.check_languages({idlang: alpha2})

def test_tmdb(self):
# examples from http://api.themoviedb.org/2.1/language-tags
for lang in ['en-US', 'en-CA', 'es-MX', 'fr-PF']:
self.assertEqual(lang, str(Language.fromguessit(lang)))
assert lang == str(Language.fromguessit(lang))

def test_subtitulos(self):
languages = {'English (US)': 'en-US', 'English (UK)': 'en-UK', 'English': 'en',
Expand All @@ -118,13 +117,5 @@ def test_thesubdb(self):
self.check_languages(languages)

def test_exceptions(self):
self.assertEqual(Language.fromguessit('br'), Language.fromguessit('pt(br)'))

self.assertEqual(Language.fromguessit('unknown'),
Language.fromguessit('und'))


suite = allTests(TestLanguage)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
assert Language.fromguessit('br') == Language.fromguessit('pt(br)')
assert Language.fromguessit('unknown') == Language.fromguessit('und')
5 changes: 0 additions & 5 deletions guessit/test/test_main.py
Expand Up @@ -62,8 +62,3 @@ def test_filename(self):
__main__.main(["-t", "episode", "A.Serie.S02E06.avi"], False)
__main__.main(["-i", "hash_mpc", file_in_same_dir(__file__, "1MB")], False)
__main__.main(["-i", "hash_md5", file_in_same_dir(__file__, "1MB")], False)

suite = allTests(TestMain)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
40 changes: 17 additions & 23 deletions guessit/test/test_matchtree.py
Expand Up @@ -52,42 +52,36 @@ def test_base_tree(self):
t.partition((3, 7, 20))
leaves = list(t.leaves())

self.assertEqual(leaves[0].span, (0, 3))
assert leaves[0].span == (0, 3)

self.assertEqual('One', leaves[0].value)
self.assertEqual(' Two', leaves[1].value)
self.assertEqual(' Three(Three)', leaves[2].value)
self.assertEqual(' Four', leaves[3].value)
assert 'One' == leaves[0].value
assert ' Two' == leaves[1].value
assert ' Three(Three)' == leaves[2].value
assert ' Four' == leaves[3].value

leaves[2].partition((1, 6, 7, 12))
three_leaves = list(leaves[2].leaves())

self.assertEqual('Three', three_leaves[1].value)
self.assertEqual('Three', three_leaves[3].value)
assert 'Three' == three_leaves[1].value
assert 'Three' == three_leaves[3].value

leaves = list(t.leaves())

self.assertEqual(len(leaves), 8)
assert len(leaves) == 8

self.assertEqual(leaves[5], three_leaves[3])
assert leaves[5] == three_leaves[3]

self.assertEqual(t.previous_leaf(leaves[5]), leaves[4])
self.assertEqual(t.next_leaf(leaves[5]), leaves[6])
assert t.previous_leaf(leaves[5]) == leaves[4]
assert t.next_leaf(leaves[5]) == leaves[6]

self.assertEqual(t.next_leaves(leaves[5]), [leaves[6], leaves[7]])
self.assertEqual(t.previous_leaves(leaves[5]), [leaves[4], leaves[3], leaves[2], leaves[1], leaves[0]])
assert t.next_leaves(leaves[5]) == [leaves[6], leaves[7]]
assert t.previous_leaves(leaves[5]) == [leaves[4], leaves[3], leaves[2], leaves[1], leaves[0]]

self.assertEqual(t.next_leaf(leaves[7]), None)
self.assertEqual(t.previous_leaf(leaves[0]), None)
assert t.next_leaf(leaves[7]) is None
assert t.previous_leaf(leaves[0]) is None

self.assertEqual(t.next_leaves(leaves[7]), [])
self.assertEqual(t.previous_leaves(leaves[0]), [])
assert t.next_leaves(leaves[7]) == []
assert t.previous_leaves(leaves[0]) == []

def test_match(self):
self.checkFields(keywords, guess_info)


suite = allTests(TestMatchTree)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)
6 changes: 0 additions & 6 deletions guessit/test/test_movie.py
Expand Up @@ -27,9 +27,3 @@ class TestMovie(TestGuessit):
def testMovies(self):
self.checkMinimumFieldsCorrect(filetype='movie',
filename='movies.yaml')


suite = allTests(TestMovie)

if __name__ == '__main__':
TextTestRunner(verbosity=2).run(suite)

0 comments on commit f637f05

Please sign in to comment.