<commit_before>from __future__ import unicode_literals

from datetime import date

from mopidy.scanner import Scanner, translator
from mopidy.models import Track, Artist, Album

from tests import unittest, path_to_data_dir


class FakeGstDate(object):
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day


class TranslatorTest(unittest.TestCase):
    def setUp(self):
        self.data = {
            'uri': 'uri',
            'album': 'albumname',
            'track-number': 1,
            'artist': 'name',
            'album-artist': 'albumartistname',
            'title': 'trackname',
            'track-count': 2,
            'date': FakeGstDate(2006, 1, 1,),
            'container-format': 'ID3 tag',
            'duration': 4531,
            'musicbrainz-trackid': 'mbtrackid',
            'musicbrainz-albumid': 'mbalbumid',
            'musicbrainz-artistid': 'mbartistid',
            'musicbrainz-albumartistid': 'mbalbumartistid',
        }

        self.album = {
            'name': 'albumname',
            'num_tracks': 2,
            'musicbrainz_id': 'mbalbumid',
        }

        self.artist = {
            'name': 'name',
            'musicbrainz_id': 'mbartistid',
        }

        self.albumartist = {
            'name': 'albumartistname',
            'musicbrainz_id': 'mbalbumartistid',
        }

        self.track = {
            'uri': 'uri',
            'name': 'trackname',
            'date': date(2006, 1, 1),
            'track_no': 1,
            'length': 4531,
            'musicbrainz_id': 'mbtrackid',
        }

    def build_track(self):
        if self.albumartist:
            self.album['artists'] = [Artist(**self.albumartist)]
        self.track['album'] = Album(**self.album)
        self.track['artists'] = [Artist(**self.artist)]
        return Track(**self.track)

    def check(self):
        expected = self.build_track()
        actual = translator(self.data)
        self.assertEqual(expected, actual)

    def test_basic_data(self):
        self.check()

    def test_missing_track_number(self):
        del self.data['track-number']
        del self.track['track_no']
        self.check()<commit_msg>scanner: Update test case<commit_after>from __future__ import unicode_literals

from mopidy.scanner import Scanner, translator
from mopidy.models import Track, Artist, Album

from tests import unittest, path_to_data_dir


class FakeGstDate(object):
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day


class TranslatorTest(unittest.TestCase):
    def setUp(self):
        self.data = {
            'uri': 'uri',
            'album': 'albumname',
            'track-number': 1,
            'artist': 'name',
            'album-artist': 'albumartistname',
            'title': 'trackname',
            'track-count': 2,
            'date': FakeGstDate(2006, 1, 1,),
            'container-format': 'ID3 tag',
            'duration': 4531,
            'musicbrainz-trackid': 'mbtrackid',
            'musicbrainz-albumid': 'mbalbumid',
            'musicbrainz-artistid': 'mbartistid',
            'musicbrainz-albumartistid': 'mbalbumartistid',
        }

        self.album = {
            'name': 'albumname',
            'num_tracks': 2,
            'musicbrainz_id': 'mbalbumid',
        }

        self.artist = {
            'name': 'name',
            'musicbrainz_id': 'mbartistid',
        }

        self.albumartist = {
            'name': 'albumartistname',
            'musicbrainz_id': 'mbalbumartistid',
        }

        self.track = {
            'uri': 'uri',
            'name': 'trackname',
            'date': '2006-01-01',
            'track_no': 1,
            'length': 4531,
            'musicbrainz_id': 'mbtrackid',
        }

    def build_track(self):
        if self.albumartist:
            self.album['artists'] = [Artist(**self.albumartist)]
        self.track['album'] = Album(**self.album)
        self.track['artists'] = [Artist(**self.artist)]
        return Track(**self.track)

    def check(self):
        expected = self.build_track()
        actual = translator(self.data)
        self.assertEqual(expected, actual)

    def test_basic_data(self):
        self.check()

    def test_missing_track_number(self):
        del self.data['track-number']
        del self.track['track_no']
        self.check()
{'fraction_non_alphanumeric': 0.13487953163701868, 'fraction_numerical': 0.011709074532762891, 'mean_word_length': 1.928147659854977, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7353147', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1362, 'n_words': 266}