<commit_before>from __future__ import unicode_literals, division, absolute_import
from flexget.plugins.parsers.parser_guessit import ParserGuessit
from flexget.plugins.parsers.parser_internal import ParserInternal
from tests import FlexGetBase, build_parser_function
from flexget.utils.qualities import Quality


class TestQualityModule(object):

    def test_get(self):
        assert not Quality(), 'unknown quality is not false'
        assert Quality('foobar') == Quality(), 'unknown not returned'

    def test_common_name(self):
        for test_val in ('720p', '1280x720'):
            got_val = Quality(test_val).name
            assert got_val == '720p', got_val


class QualityParser(object):

    def test_qualities(self):
        items = [('Test.File 1080p.web-dl', '1080p webdl'),
                 ('Test.File.web-dl.1080p', '1080p webdl'),
                 ('Test.File.WebHD.720p', '720p webdl'),
                 ('Test.File.720p.bluray', '720p bluray'),
                 ('Test.File.1080p.bluray', '1080p bluray'),
                 ('Test.File.1080p.cam', '1080p cam'),
                 ('A Movie 2011 TS 576P XviD-DTRG', '576p ts xvid'),

                 ('Test.File.720p.bluray.r5', '720p r5'),
                 ('Test.File.1080p.bluray.rc', '1080p r5'),

                 # 10bit
                 ('Test.File.480p.10bit', '480p 10bit'),
                 ('Test.File.720p.10bit', '720p 10bit'),
                 ('Test.File.720p.bluray.10bit', '720p bluray 10bit'),
                 ('Test.File.1080p.10bit', '1080p 10bit'),
                 ('Test.File.1080p.bluray.10bit', '1080p bluray 10bit'),

                 ('Test.File.720p.webdl', '720p webdl'),
                 ('Test.File.1280x720_web dl', '720p webdl'),
                 ('Test.File.720p.h264.web.dl', '720p webdl h264'),
                 ('Test.File.1080p.webhd.x264', '1080p webdl h264'),
                 ('Test.File.web-dl', 'webdl'),
                 ('Test.File.720P', '720p'),
                 ('Test.File.1920x1080', '1080p'),
                 ('Test.File.1080i', '1080i'),
                 ('Test File blurayrip', 'bluray'),
                 ('Test.File.br-rip', 'bluray'),
                 ('Test.File.720px', '720p'),

                 ('Test.File.dvd.rip', 'dvdrip'),
                 ('Test.File.dvd.rip.r5', 'r5'),

                 ('Test.File.[576p][00112233].mkv', '576p'),

                 ('Test.TS.FooBar', 'ts'),

                 ('Test.File.360p.avi', '360p'),
                 ('Test.File.[360p].mkv', '360p'),
                 ('Test.File.368.avi', '368p'),
                 ('Test.File.720p.hdtv.avi', '720p hdtv'),
                 ('Test.File.1080p.hdtv.avi', '1080p hdtv'),
                 ('Test.File.720p.preair.avi', '720p preair'),
                 #('Test.File.ts.dvdrip.avi', 'ts'), This should no exists. Having Telesync and DVDRip is a non-sense.
                 ('Test.File.HDTS.blah', 'ts'),
                 #('Test.File.HDCAM.bluray.lie', 'cam'), This should no exists. Having Cam and Bluray is a non-sense.

                 # Test qualities as part of words. #1593
                 ('Tsar.File.720p', '720p'),
                 ('Camera.1080p', '1080p'),

                 # Some audio formats
                 ('Test.File.DTSHDMA', 'dtshd'),
                 ('Test.File.DTSHD.MA', 'dtshd'),
                 ('Test.File.DTS.HDMA', 'dtshd'),
                 ('Test.File.dts.hd.ma', 'dtshd'),
                 ('Test.File.DTS.HD', 'dtshd'),
                 ('Test.File.DTSHD', 'dtshd'),
                 ('Test.File.DTS', 'dts'),
                 ('Test.File.truehd', 'truehd')]

        item = 'Test.File.DTSHDMA', 'dtshd'

        quality = self.parser.parse_movie(item[0]).quality
        assert quality == item[1], '`%s` quality should be `%s` not `%s`' % (item[0], item[1], quality)

        for item in items:
            quality = self.parser.parse_movie(item[0]).quality
            assert quality == item[1], '`%s` quality should be `%s` not `%s`' % (item[0], item[1], quality)


class TestInternalQualityParser(QualityParser):
    parser = ParserInternal()


class TestGuessitQualityParser(QualityParser):
    parser = ParserGuessit()


class TestFilterQuality(FlexGetBase):

    __yaml__ = """
        templates:
          global:
            mock:
              - {title: 'Smoke.1280x720'}
              - {title: 'Smoke.HDTV'}
              - {title: 'Smoke.cam'}
              - {title: 'Smoke.HR'}
            accept_all: yes
        tasks:
          qual:
            quality:
              - hdtv
              - 720p
          min:
            quality: HR+
          max:
            quality: "<=cam <HR"
          min_max:
            quality: HR-720i
    """

    def test_quality(self):<commit_msg>Change qualities tests so that guessit mismatches are skipped and logged, not failed<commit_after>from __future__ import unicode_literals, division, absolute_import

from nose.plugins.skip import SkipTest

from flexget.plugins.parsers.parser_guessit import ParserGuessit
from flexget.plugins.parsers.parser_internal import ParserInternal
from flexget.utils.qualities import Quality
from tests import FlexGetBase, build_parser_function


class TestQualityModule(object):

    def test_get(self):
        assert not Quality(), 'unknown quality is not false'
        assert Quality('foobar') == Quality(), 'unknown not returned'

    def test_common_name(self):
        for test_val in ('720p', '1280x720'):
            got_val = Quality(test_val).name
            assert got_val == '720p', got_val


class QualityParser(object):

    def get_quality_failures(self):
        items = [('Test.File 1080p.web-dl', '1080p webdl'),
                 ('Test.File.web-dl.1080p', '1080p webdl'),
                 ('Test.File.WebHD.720p', '720p webdl'),
                 ('Test.File.720p.bluray', '720p bluray'),
                 ('Test.File.1080p.bluray', '1080p bluray'),
                 ('Test.File.1080p.cam', '1080p cam'),
                 ('A Movie 2011 TS 576P XviD-DTRG', '576p ts xvid'),

                 ('Test.File.720p.bluray.r5', '720p r5'),
                 ('Test.File.1080p.bluray.rc', '1080p r5'),

                 # 10bit
                 ('Test.File.480p.10bit', '480p 10bit'),
                 ('Test.File.720p.10bit', '720p 10bit'),
                 ('Test.File.720p.bluray.10bit', '720p bluray 10bit'),
                 ('Test.File.1080p.10bit', '1080p 10bit'),
                 ('Test.File.1080p.bluray.10bit', '1080p bluray 10bit'),

                 ('Test.File.720p.webdl', '720p webdl'),
                 ('Test.File.1280x720_web dl', '720p webdl'),
                 ('Test.File.720p.h264.web.dl', '720p webdl h264'),
                 ('Test.File.1080p.webhd.x264', '1080p webdl h264'),
                 ('Test.File.web-dl', 'webdl'),
                 ('Test.File.720P', '720p'),
                 ('Test.File.1920x1080', '1080p'),
                 ('Test.File.1080i', '1080i'),
                 ('Test File blurayrip', 'bluray'),
                 ('Test.File.br-rip', 'bluray'),
                 ('Test.File.720px', '720p'),

                 ('Test.File.dvd.rip', 'dvdrip'),
                 ('Test.File.dvd.rip.r5', 'r5'),

                 ('Test.File.[576p][00112233].mkv', '576p'),

                 ('Test.TS.FooBar', 'ts'),

                 ('Test.File.360p.avi', '360p'),
                 ('Test.File.[360p].mkv', '360p'),
                 ('Test.File.368.avi', '368p'),
                 ('Test.File.720p.hdtv.avi', '720p hdtv'),
                 ('Test.File.1080p.hdtv.avi', '1080p hdtv'),
                 ('Test.File.720p.preair.avi', '720p preair'),
                 #('Test.File.ts.dvdrip.avi', 'ts'), This should no exists. Having Telesync and DVDRip is a non-sense.
                 ('Test.File.HDTS.blah', 'ts'),
                 #('Test.File.HDCAM.bluray.lie', 'cam'), This should no exists. Having Cam and Bluray is a non-sense.

                 # Test qualities as part of words. #1593
                 ('Tsar.File.720p', '720p'),
                 ('Camera.1080p', '1080p'),

                 # Some audio formats
                 ('Test.File.DTSHDMA', 'dtshd'),
                 ('Test.File.DTSHD.MA', 'dtshd'),
                 ('Test.File.DTS.HDMA', 'dtshd'),
                 ('Test.File.dts.hd.ma', 'dtshd'),
                 ('Test.File.DTS.HD', 'dtshd'),
                 ('Test.File.DTSHD', 'dtshd'),
                 ('Test.File.DTS', 'dts'),
                 ('Test.File.truehd', 'truehd'),
                 ('Test.File.DTSHDMA', 'dtshd')]

        failures = []
        for item in items:
            quality = self.parser.parse_movie(item[0]).quality
            if quality != item[1]:
                failures.append('`%s` quality should be `%s` not `%s`' % (item[0], item[1], quality))
        return failures



class TestInternalQualityParser(QualityParser):
    parser = ParserInternal()

    def test_qualities(self):
        failures = self.get_quality_failures()
        assert not failures, '%s failures:\n%s' % (len(failures), '\n'.join(failures))


class TestGuessitQualityParser(QualityParser):
    parser = ParserGuessit()

    def test_qualities(self):
        failures = self.get_quality_failures()
        if failures:
            raise SkipTest('Guessit quality parser does not match FlexGet: %s' % ', '.join(failures))



class TestFilterQuality(FlexGetBase):

    __yaml__ = """
        templates:
          global:
            mock:
              - {title: 'Smoke.1280x720'}
              - {title: 'Smoke.HDTV'}
              - {title: 'Smoke.cam'}
              - {title: 'Smoke.HR'}
            accept_all: yes
        tasks:
          qual:
            quality:
              - hdtv
              - 720p
          min:
            quality: HR+
          max:
            quality: "<=cam <HR"
          min_max:
            quality: HR-720i
    """

    def test_quality(self):
{'fraction_non_alphanumeric': 0.1556722901303162, 'fraction_numerical': 0.06162238609960602, 'mean_word_length': 1.743142144638404, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5404360', 'n_tokens_mistral': 3579, 'n_tokens_neox': 3063, 'n_words': 631}