<s> from __future__ import division , absolute_import , print_function <EOL> import time <EOL> from datetime import datetime <EOL> from test . _common import unittest <EOL> from test . helper import TestHelper <EOL> from beets . util . confit import ConfigValueError <EOL> class TypesPluginTest ( unittest . TestCase , TestHelper ) : <EOL> def setUp ( self ) : <EOL> self . setup_beets ( ) <EOL> self . load_plugins ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> self . unload_plugins ( ) <EOL> self . teardown_beets ( ) <EOL> def test_integer_modify_and_query ( self ) : <EOL> self . config [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT:int>' } <EOL> item = self . add_item ( artist = u'<STR_LIT>' ) <EOL> out = self . list ( u'<STR_LIT>' ) <EOL> self . assertEqual ( u'<STR_LIT>' , out ) <EOL> self . modify ( u'<STR_LIT>' ) <EOL> item . load ( ) <EOL> self . assertEqual ( item [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> out = self . list ( u'<STR_LIT>' ) <EOL> self . assertIn ( b'<STR_LIT>' , out ) <EOL> def test_album_integer_modify_and_query ( self ) : <EOL> self . config [ '<STR_LIT>' ] = { '<STR_LIT>' : u'<STR_LIT:int>' } <EOL> album = self . add_album ( albumartist = u'<STR_LIT>' ) <EOL> out = self . list_album ( u'<STR_LIT>' ) <EOL> self . assertEqual ( u'<STR_LIT>' , out ) <EOL> self . modify ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> album . load ( ) <EOL> self . assertEqual ( album [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> out = self . list_album ( u'<STR_LIT>' ) <EOL> self . assertIn ( b'<STR_LIT>' , out ) <EOL> def test_float_modify_and_query ( self ) : <EOL> self . config [ '<STR_LIT>' ] = { '<STR_LIT>' : u'<STR_LIT:float>' } <EOL> item = self . add_item ( artist = u'<STR_LIT>' ) <EOL> self . modify ( u'<STR_LIT>' ) <EOL> item . load ( ) <EOL> self . assertEqual ( item [ '<STR_LIT>' ] , - <NUM_LIT> ) <EOL> out = self . list ( u'<STR_LIT>' ) <EOL> self . assertIn ( b'<STR_LIT>' , out ) <EOL> def test_bool_modify_and_query ( self ) : <EOL> self . config [ '<STR_LIT>' ] = { '<STR_LIT>' : u'<STR_LIT:bool>' } <EOL> true = self . add_item ( artist = u'<STR_LIT:true>' ) <EOL> false = self . add_item ( artist = u'<STR_LIT:false>' ) <EOL> self . add_item ( artist = u'<STR_LIT>' ) <EOL> self . modify ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> true . load ( ) <EOL> self . assertEqual ( true [ '<STR_LIT>' ] , True ) <EOL> self . modify ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> false . load ( ) <EOL> self . assertEqual ( false [ '<STR_LIT>' ] , False ) <EOL> out = self . list ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> self . assertEqual ( u'<STR_LIT>' , out ) <EOL> out = self . list ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> def test_date_modify_and_query ( self ) : <EOL> self . config [ '<STR_LIT>' ] = { '<STR_LIT>' : u'<STR_LIT:date>' } <EOL> self . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> old = self . add_item ( artist = u'<STR_LIT>' ) <EOL> new = self . add_item ( artist = u'<STR_LIT>' ) <EOL> self . modify ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> old . load ( ) <EOL> self . assertEqual ( old [ '<STR_LIT>' ] , mktime ( <NUM_LIT> , <NUM_LIT:0> <NUM_LIT:1> , <NUM_LIT:0> <NUM_LIT:1> ) ) <EOL> self . modify ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> new . load ( ) <EOL> self . assertEqual ( new [ '<STR_LIT>' ] , mktime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:30> ) ) <EOL> out = self . list ( u'<STR_LIT>' , u'<STR_LIT>' ) <EOL> self . assertEqual ( u'<STR_LIT>' , out ) <EOL> def test_unknown_type_error ( self ) : <EOL> self . config [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with self . assertRaises ( ConfigValueError ) : <EOL> self . run_command ( u'<STR_LIT>' ) <EOL> def modify ( self , * args ) : <EOL> return self . run_with_output ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <EOL> u'<STR_LIT>' , * args ) <EOL> def list ( self , query , fmt = u'<STR_LIT>' ) : <EOL> return self . run_with_output ( u'<STR_LIT>' , u'<STR_LIT>' , fmt , query ) . strip ( ) <EOL> def list_album ( self , query , fmt = u'<STR_LIT>' ) : <EOL> return self . run_with_output ( u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , fmt , query ) . strip ( ) <EOL> def mktime ( * args ) : <EOL> return time . mktime ( datetime ( * args ) . timetuple ( ) ) <EOL> def suite ( ) : <EOL> return unittest . TestLoader ( ) . loadTestsFromName ( __name__ ) <EOL> if __name__ == b'<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
