<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import , print_function <EOL> import os <EOL> from mock import patch , Mock <EOL> from test . _common import unittest <EOL> from test . helper import TestHelper <EOL> from beetsplug . permissions import ( check_permissions , <EOL> convert_perm , <EOL> dirs_in_library ) <EOL> class PermissionsPluginTest ( unittest . TestCase , TestHelper ) : <EOL> def setUp ( self ) : <EOL> self . setup_beets ( ) <EOL> self . load_plugins ( '<STR_LIT>' ) <EOL> self . config [ '<STR_LIT>' ] = { <EOL> '<STR_LIT:file>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> def tearDown ( self ) : <EOL> self . teardown_beets ( ) <EOL> self . unload_plugins ( ) <EOL> def test_permissions_on_album_imported ( self ) : <EOL> self . do_thing ( True ) <EOL> def test_permissions_on_item_imported ( self ) : <EOL> self . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> self . do_thing ( True ) <EOL> @ patch ( "<STR_LIT>" , Mock ( ) ) <EOL> def test_failing_to_set_permissions ( self ) : <EOL> self . do_thing ( False ) <EOL> def do_thing ( self , expect_success ) : <EOL> def get_stat ( v ) : <EOL> return os . stat ( <EOL> os . path . join ( self . temp_dir , '<STR_LIT>' , * v ) ) . st_mode & <NUM_LIT> <EOL> self . importer = self . create_importer ( ) <EOL> typs = [ '<STR_LIT:file>' , '<STR_LIT>' ] <EOL> self . exp_perms = { <EOL> True : { k : convert_perm ( self . config [ '<STR_LIT>' ] [ k ] . get ( ) ) <EOL> for k in typs } , <EOL> False : { k : get_stat ( v ) <EOL> for ( k , v ) in zip ( typs , ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( ) ) ) } } <EOL> self . importer . run ( ) <EOL> item = self . lib . items ( ) . get ( ) <EOL> self . assertPerms ( item . path , '<STR_LIT:file>' , expect_success ) <EOL> for path in dirs_in_library ( self . lib . directory , item . path ) : <EOL> self . assertPerms ( path , '<STR_LIT>' , expect_success ) <EOL> def assertPerms ( self , path , typ , expect_success ) : <EOL> for x in [ ( True , self . exp_perms [ expect_success ] [ typ ] , '<STR_LIT>' ) , <EOL> ( False , self . exp_perms [ not expect_success ] [ typ ] , '<STR_LIT>' ) ] : <EOL> self . assertEqual ( x [ <NUM_LIT:0> ] , check_permissions ( path , x [ <NUM_LIT:1> ] ) , <EOL> msg = u'<STR_LIT>' . format ( <EOL> path , oct ( os . stat ( path ) . st_mode ) , x [ <NUM_LIT:2> ] , oct ( x [ <NUM_LIT:1> ] ) ) ) <EOL> def test_convert_perm_from_string ( self ) : <EOL> self . assertEqual ( convert_perm ( '<STR_LIT>' ) , <NUM_LIT:8> ) <EOL> def suite ( ) : <EOL> return unittest . TestLoader ( ) . loadTestsFromName ( __name__ ) <EOL> if __name__ == b'<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
