self.assertEqual(d['title'], ['bar']) def test_apply_tags(self): p = self.get_meta_store() p.set(self.test_data_path, {'artist': 'foo', 'title': 'bar'}) f = SimpleMutagenFile(self.test_data_path) self.assertEqual(f['artist'], ['foo']) self.assertEqual(f['title'], ['bar']) def test_apply_does_not_apply_path_name_based_tags(self): path_name_based_tags = ('extension', 'e', 'filename', 'f', 'parent', 'p') p = self.get_meta_store() d = p.get(self.test_data_path) for t in path_name_based_tags: assert t in d self.assertRaises(UnsettableKeyError, p.set, self.test_data_path, d) def test_apply_does_apply_arbitrary_non_path_name_based_tags(self): p = self.get_meta_store() p.set(self.test_data_path, {'bizz': 'buzz'}) f = SimpleMutagenFile(self.test_data_path) self.assertEqual(f['bizz'], ['buzz']) manager.add_test_case_class(PyTagsFileSystemMetaStoreTestCase)
def add_blackbox_test_class(cls): manager.add_test_case_class(cls) manager.add_test_case_class(mixin_singlethreaded(cls))
self.assertEqual(d['artist'], ['foo']) self.assertEqual(d['title'], ['bar']) def test_apply_tags(self): p = self.get_meta_store() p.set(self.test_data_path, {'artist': 'foo', 'title': 'bar'}) f = SimpleMutagenFile(self.test_data_path) self.assertEqual(f['artist'], ['foo']) self.assertEqual(f['title'], ['bar']) def test_apply_does_not_apply_path_name_based_tags(self): path_name_based_tags = ( 'extension', 'e', 'filename', 'f', 'parent', 'p') p = self.get_meta_store() d = p.get(self.test_data_path) for t in path_name_based_tags: assert t in d self.assertRaises(UnsettableKeyError, p.set, self.test_data_path, d) def test_apply_does_apply_arbitrary_non_path_name_based_tags(self): p = self.get_meta_store() p.set(self.test_data_path, {'bizz': 'buzz'}) f = SimpleMutagenFile(self.test_data_path) self.assertEqual(f['bizz'], ['buzz']) manager.add_test_case_class(PyTagsFileSystemMetaStoreTestCase)
# # pytagsfs is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License version 2 as published by the Free # Software Foundation. # # A copy of the license has been included in the COPYING file. import os from unittest import TestCase from pytagsfs.metastore.testlines import TestLinesMetaStore from pytagsfs.values import Values from manager import manager from common import TestWithDir class TestLinesMetaStoreTestCase(TestWithDir): test_dir_prefix = 'mts' def test(self): filename = os.path.join(self.test_dir, 'foo') store = TestLinesMetaStore() store.set(filename, Values.from_flat_dict({'a': 'qux'})) try: self.assertEqual(store.get(filename), Values({'a': ['qux']})) finally: os.unlink(filename) manager.add_test_case_class(TestLinesMetaStoreTestCase)
if count > len(dirs) + 1: raise AssertionError('waited too long for events') self._check_removals(removals, dirs) def _check_removals(self, removals, dirs): self.assertEqual(removals, dirs) if PLATFORM not in NO_INOTIFY_PLATFORMS: class InotifyxSourceTreeMonitorTestCase(_SourceTreeMonitorTestCase): sourcetreemoncls = InotifyxSourceTreeMonitor sets_is_dir = True manager.add_test_case_class(InotifyxSourceTreeMonitorTestCase) class DeferredInotifyxSourceTreeMonitorTestCase(_SourceTreeMonitorTestCase ): sourcetreemoncls = DeferredInotifyxSourceTreeMonitor sets_is_dir = True manager.add_test_case_class(DeferredInotifyxSourceTreeMonitorTestCase) if PLATFORM not in NO_GAMIN_PLATFORMS: class GaminSourceTreeMonitorTestCase(_SourceTreeMonitorTestCase): sourcetreemoncls = GaminSourceTreeMonitor sets_is_dir = False def _check_removals(self, removals, dirs):
fake_path1 = join_path_abs([self.p('bar')]) fake_path2 = join_path_abs([self.p('baz')]) fake_path3 = join_path_abs([self.p('qux')]) self._create_file(real_path, content) try: self._init(ContentMetaStore(), u'/%c') self.source_tree_rep.start() try: self.assertEqual( self.source_tree_rep.get_real_path(fake_path1), real_path) self.assertEqual( self.source_tree_rep.get_real_path(fake_path2), real_path) self.assertEqual( self.source_tree_rep.get_real_path(fake_path3), real_path) self.assertEqual( self.source_tree_rep.get_fake_paths(real_path), [fake_path1, fake_path2, fake_path3]) finally: self.source_tree_rep.stop() finally: self._remove_file(real_path) manager.add_test_case_class(SourceTreeRepresentationTestCase) manager.add_test_case_class(mixin_unicode(SourceTreeRepresentationTestCase)) manager.add_test_case_class( mixin_pathpropcache(SourceTreeRepresentationTestCase)) manager.add_test_case_class( mixin_unicode(mixin_pathpropcache(SourceTreeRepresentationTestCase))) manager.add_doc_test_cases_from_module(__name__, 'pytagsfs.sourcetree')
self.assertEqual( self.source_tree.get_absolute_path(unicode_path_sep), self.root, ) # Paths must begin with a slash. self.assertRaises( ValueError, self.source_tree.get_absolute_path, u'a', ) # Paths must not end with a slash. path = os.path.join(unicode_path_sep, u'a', u'') self.assertTrue(path.endswith(unicode_path_sep)) self.assertRaises( ValueError, self.source_tree.get_absolute_path, path, ) manager.add_test_case_class(SourceTreeTestCase) class RootSourceTreeTestCase(SourceTreeTestCase): root = unicode_path_sep manager.add_test_case_class(RootSourceTreeTestCase)
fake_path2 = join_path_abs([self.p('baz')]) fake_path3 = join_path_abs([self.p('qux')]) self._create_file(real_path, content) try: self._init(ContentMetaStore(), u'/%c') self.source_tree_rep.start() try: self.assertEqual( self.source_tree_rep.get_real_path(fake_path1), real_path) self.assertEqual( self.source_tree_rep.get_real_path(fake_path2), real_path) self.assertEqual( self.source_tree_rep.get_real_path(fake_path3), real_path) self.assertEqual( self.source_tree_rep.get_fake_paths( real_path), [fake_path1, fake_path2, fake_path3]) finally: self.source_tree_rep.stop() finally: self._remove_file(real_path) manager.add_test_case_class(SourceTreeRepresentationTestCase) manager.add_test_case_class(mixin_unicode(SourceTreeRepresentationTestCase)) manager.add_test_case_class( mixin_pathpropcache(SourceTreeRepresentationTestCase)) manager.add_test_case_class( mixin_unicode(mixin_pathpropcache(SourceTreeRepresentationTestCase))) manager.add_doc_test_cases_from_module(__name__, 'pytagsfs.sourcetree')
def test_fill(self): self.assertEqual( self.pattern.fill(self.substitution_pattern_mapping), self.substitution_pattern_filled_string, ) class ShortKeySubstitutionPatternTestCase( SubstitutionPatternTestMixin, TestCase, ): pattern_string = '%a %b %c' substitution_pattern_mapping = {'a': 'foo', 'b': 'bar', 'c': 'baz'} substitution_pattern_filled_string = 'foo bar baz' manager.add_test_case_class(ShortKeySubstitutionPatternTestCase) class LongKeySubstitutionPatternTestCase( SubstitutionPatternTestMixin, TestCase, ): pattern_string = '%{aye} %{bee} %{see}' substitution_pattern_mapping = {'aye': 'foo', 'bee': 'bar', 'see': 'baz'} substitution_pattern_filled_string = 'foo bar baz' manager.add_test_case_class(LongKeySubstitutionPatternTestCase) class MixedKeySubstitutionPatternTestCase( SubstitutionPatternTestMixin,
def test_diff3_with_partial_value_removal(self): base = Values({'a': [u'foo', u'bar'], 'b': [u'baz'], 'd': [u'qux']}) old = Values({'a': [u'foo'], 'b': [u'baz']}) new = Values({'b': [u'baz']}) self.assertEqual(Values.diff3(base, old, new), Values({'a': [u'bar']})) def test_diff2_with_value_change(self): old = Values({'a': [u'foo'], 'b': [u'baz']}) new = Values({'a': [u'boink'], 'b': [u'baz']}) self.assertEqual(Values.diff2(old, new), Values({'a': [u'boink']})) def test_diff3_with_partial_value_change(self): base = Values({'a': [u'foo', u'bar'], 'b': [u'baz'], 'd': [u'qux']}) old = Values({'a': [u'foo'], 'b': [u'baz']}) new = Values({'a': [u'boink'], 'b': [u'baz']}) self.assertEqual( Values.diff3(base, old, new), Values({'a': [u'bar', u'boink']}), ) def test_combine(self): a = Values({'a': [u'foo'], 'b': [u'baz', u'bar']}) b = Values({'b': [u'qux', u'bar', u'quxx']}) self.assertEqual( Values.combine([a, b]), Values({'a': [u'foo'], 'b': [u'baz', u'bar', u'qux', u'quxx']}), ) manager.add_test_case_class(TestValues)
self.assertEqual( which(self.cls([segment, segment])), '%s([%s, %s])' % (self.cls_name, repr(segment), repr(segment)), ) def test_str(self): return self._test_str_unicode_repr(str) def test_unicode(self): return self._test_str_unicode_repr(unicode) def test_repr(self): return self._test_str_unicode_repr(repr) manager.add_test_case_class(SegmentContainerTestCase) class RegexTestCase(SegmentContainerTestCase): cls = Regex cls_name = 'Regex' def test_str(self): self.assertEqual(str(Regex()), '') self.assertEqual(str(Regex([SimpleExpression('foo')])), 'foo') def test_unicode(self): self.assertEqual(unicode(Regex()), u'') self.assertEqual(unicode(Regex([SimpleExpression(u'foo')])), u'foo') def test_empty_regex(self):
# This file is part of the pytagsfs software package. # # pytagsfs is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License version 2 as published by the Free # Software Foundation. # # A copy of the license has been included in the COPYING file. from manager import manager from pytagsfs.pathstore.pytypes import PyTypesPathStore from pathstore import _PathStoreTestCase from common import _UnicodePathsMixin class PyTypesPathStoreTestCase(_PathStoreTestCase): path_store_class = PyTypesPathStore manager.add_test_case_class(PyTypesPathStoreTestCase) class PyTypesPathStoreUnicodeTestCase(_UnicodePathsMixin, _PathStoreTestCase): path_store_class = PyTypesPathStore manager.add_test_case_class(PyTypesPathStoreUnicodeTestCase) manager.add_doc_test_cases_from_module(__name__, 'pytagsfs.pathstore.pytypes')
# Copyright (c) 2007-2008 Forest Bond. # This file is part of the pytagsfs software package. # # pytagsfs is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License version 2 as published by the Free # Software Foundation. # # A copy of the license has been included in the COPYING file. from unittest import TestCase from pytagsfs.metastore.mutagen_ import MutagenFileMetaStore from manager import manager class MutagenFileMetaStoreTestCase(TestCase): def test_post_process(self): store = MutagenFileMetaStore() tags = {'n': ['1']} store.post_process(tags) self.assertEqual( tags, {'n': ['1'], 'N': ['01'], 'TRACKNUMBER': ['01']}, ) manager.add_test_case_class(MutagenFileMetaStoreTestCase)
if count > len(dirs) + 1: raise AssertionError('waited too long for events') self._check_removals(removals, dirs) def _check_removals(self, removals, dirs): self.assertEqual(removals, dirs) if PLATFORM not in NO_INOTIFY_PLATFORMS: class InotifyxSourceTreeMonitorTestCase(_SourceTreeMonitorTestCase): sourcetreemoncls = InotifyxSourceTreeMonitor sets_is_dir = True manager.add_test_case_class(InotifyxSourceTreeMonitorTestCase) class DeferredInotifyxSourceTreeMonitorTestCase(_SourceTreeMonitorTestCase): sourcetreemoncls = DeferredInotifyxSourceTreeMonitor sets_is_dir = True manager.add_test_case_class(DeferredInotifyxSourceTreeMonitorTestCase) if PLATFORM not in NO_GAMIN_PLATFORMS: class GaminSourceTreeMonitorTestCase(_SourceTreeMonitorTestCase): sourcetreemoncls = GaminSourceTreeMonitor sets_is_dir = False def _check_removals(self, removals, dirs): # Gamin does not return these events in a reliable order. This
# pytagsfs is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License version 2 as published by the Free # Software Foundation. # # A copy of the license has been included in the COPYING file. import os from unittest import TestCase from pytagsfs.metastore.testlines import TestLinesMetaStore from pytagsfs.values import Values from manager import manager from common import TestWithDir class TestLinesMetaStoreTestCase(TestWithDir): test_dir_prefix = 'mts' def test(self): filename = os.path.join(self.test_dir, 'foo') store = TestLinesMetaStore() store.set(filename, Values.from_flat_dict({'a': 'qux'})) try: self.assertEqual(store.get(filename), Values({'a': ['qux']})) finally: os.unlink(filename) manager.add_test_case_class(TestLinesMetaStoreTestCase)
def get_argv(self): return [ 'pytagsfs', '-o', 'format=/%f/%f', self.source_dir.encode(ENCODING), 'mnt', ] class AccessTestCase(_BaseSingleFileOperationTestCase): def test_not_supported(self): self.assertEqual(self.filesystem.access(self.dest_file, os.F_OK), 0) manager.add_test_case_class(AccessTestCase) manager.add_test_case_class(mixin_unicode(AccessTestCase)) class BmapTestCase(_BasePyTagsFileSystemTestCase): def test_not_supported(self): try: self.filesystem.bmap(None, None, None) except FuseError, e: self.assertEqual(e.errno, errno.ENOSYS) manager.add_test_case_class(BmapTestCase) manager.add_test_case_class(mixin_unicode(BmapTestCase))
# Copyright (c) 2007-2008 Forest Bond. # This file is part of the pytagsfs software package. # # pytagsfs is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License version 2 as published by the Free # Software Foundation. # # A copy of the license has been included in the COPYING file. from manager import manager from pytagsfs.pathstore.pytypes import PyTypesPathStore from pathstore import _PathStoreTestCase from common import _UnicodePathsMixin class PyTypesPathStoreTestCase(_PathStoreTestCase): path_store_class = PyTypesPathStore manager.add_test_case_class(PyTypesPathStoreTestCase) class PyTypesPathStoreUnicodeTestCase(_UnicodePathsMixin, _PathStoreTestCase): path_store_class = PyTypesPathStore manager.add_test_case_class(PyTypesPathStoreUnicodeTestCase) manager.add_doc_test_cases_from_module(__name__, 'pytagsfs.pathstore.pytypes')