3131import  unittest .mock 
3232
3333import  logging 
34- import  pkg_resources 
34+ import  importlib . resources 
3535import  qubesappmenus 
3636import  qubesappmenus .receive 
3737
@@ -247,16 +247,19 @@ def test_005_created_appvm(self):
247247        self .ext .appmenus_init (appvm )
248248        with  open (os .path .join (self .ext .templates_dirs (tpl )[0 ],
249249                'evince.desktop' ), 'wb' ) as  f :
250-             f .write (pkg_resources .resource_string (__name__ ,
251-                 'test-data/evince.desktop.template' ))
250+             f .write (importlib .resources .files (
251+                 anchor = __name__ ).joinpath (
252+                 'test-data/evince.desktop.template' ).read_bytes ())
252253        self .ext .appmenus_create (appvm , refresh_cache = False )
253254        self .ext .appicons_create (appvm )
254255        evince_path  =  self ._make_desktop_name (appvm , 'evince.desktop' )
255256        self .assertPathExists (evince_path )
256257        with  open (evince_path , 'rb' ) as  f :
258+             new_file_bytes  =  importlib .resources .files (
259+                 anchor = __name__ ).joinpath (
260+                 'test-data/evince.desktop' ).read_bytes ()
257261            self .assertEqual (
258-                 pkg_resources .resource_string (__name__ ,
259-                     'test-data/evince.desktop' ).replace (b'%BASEDIR%' ,
262+                 new_file_bytes .replace (b'%BASEDIR%' ,
260263                    qubesappmenus .basedir .encode ()),
261264                f .read ()
262265            )
@@ -279,27 +282,34 @@ def test_006_created_appvm_custom(self):
279282        self .ext .appmenus_init (appvm )
280283        with  open (os .path .join (self .ext .templates_dirs (tpl )[0 ],
281284                'evince.desktop' ), 'wb' ) as  f :
282-             f .write (pkg_resources .resource_string (__name__ ,
283-                 'test-data/evince.desktop.template' ))
285+             evince_data  =  importlib .resources .files (
286+                 anchor = __name__ ).joinpath (
287+                 'test-data/evince.desktop.template' ).read_bytes ()
288+             f .write (evince_data )
284289        self .ext .appmenus_create (appvm , refresh_cache = False )
285290        self .ext .appicons_create (appvm )
286291
287292        with  open (os .path .join (self .ext .templates_dirs (tpl )[0 ],
288293                'xterm.desktop' ), 'wb' ) as  f :
289-             f .write (pkg_resources .resource_string (__name__ ,
290-                 'test-data/xterm.desktop.template' ))
294+             xterm_data  =  importlib .resources .files (
295+                 anchor = __name__ ).joinpath (
296+                 'test-data/xterm.desktop.template' ).read_bytes ()
297+             f .write (xterm_data )
291298        with  open (os .path .join (self .ext .templates_dirs (tpl )[0 ],
292299                'evince.desktop' ), 'wb' ) as  f :
293-             f .write (pkg_resources .resource_string (__name__ ,
294-                 'test-data/evince.desktop.template' ).
295-                 replace (b'Document Viewer' , b'Random Viewer' ))
300+             evince_data  =  importlib .resources .files (
301+                 anchor = __name__ ).joinpath (
302+                 'test-data/evince.desktop.template' ).read_bytes ()
303+             f .write (evince_data .replace (b'Document Viewer' , b'Random Viewer' ))
296304        self .ext .appmenus_update (appvm )
297305        evince_path  =  self ._make_desktop_name (appvm , 'evince.desktop' )
298306        self .assertPathExists (evince_path )
299307        with  open (evince_path , 'rb' ) as  f :
308+             evince_data  =  importlib .resources .files (
309+                 anchor = __name__ ).joinpath (
310+                 'test-data/evince.desktop' ).read_bytes ()
300311            self .assertEqual (
301-                 pkg_resources .resource_string (__name__ ,
302-                     'test-data/evince.desktop' )
312+                 evince_data 
303313                    .replace (b'%BASEDIR%' , qubesappmenus .basedir .encode ())
304314                    .replace (b'Document Viewer' , b'Random Viewer' ),
305315                f .read ()
@@ -308,9 +318,10 @@ def test_006_created_appvm_custom(self):
308318        xterm_path  =  self ._make_desktop_name (appvm , 'xterm.desktop' )
309319        self .assertPathExists (xterm_path )
310320        with  open (xterm_path , 'rb' ) as  f :
311-             self .assertEqual (
312-                 pkg_resources .resource_string (__name__ ,
313-                     'test-data/xterm.desktop' )
321+             xterm_data  =  importlib .resources .files (
322+                 anchor = __name__ ).joinpath (
323+                 'test-data/xterm.desktop' ).read_bytes ()
324+             self .assertEqual (xterm_data 
314325                    .replace (b'%BASEDIR%' , qubesappmenus .basedir .encode ()),
315326                f .read ()
316327            )
@@ -335,8 +346,10 @@ def test_007_created_dispvm(self):
335346        self .ext .appmenus_init (appvm )
336347        with  open (os .path .join (self .ext .templates_dirs (tpl )[0 ],
337348                'evince.desktop' ), 'wb' ) as  f :
338-             f .write (pkg_resources .resource_string (__name__ ,
339-                 'test-data/evince.desktop.template' ))
349+             evince_data  =  importlib .resources .files (
350+                 anchor = __name__ ).joinpath (
351+                 'test-data/evince.desktop.template' ).read_bytes ()
352+             f .write (evince_data )
340353        self .ext .appmenus_create (appvm , refresh_cache = False )
341354        self .ext .appicons_create (appvm )
342355        appmenus_dir  =  self .ext .appmenus_dir (appvm )
@@ -386,8 +399,8 @@ class PopenMockup(object):
386399                pass 
387400            self .assertEqual (service , 'qubes.GetAppmenus' )
388401            p  =  PopenMockup ()
389-             p .stdout  =  pkg_resources . resource_stream ( __name__ , 
390-                 'test-data/appmenus.input' )
402+             p .stdout  =  importlib . resources . files ( 
403+                 anchor = __name__ ). joinpath ( 'test-data/appmenus.input'  ). open ( mode = 'rb ' )
391404            p .wait  =  lambda : None 
392405            p .returncode  =  0 
393406            return  p 
@@ -509,8 +522,10 @@ def test_120_create_appvm(self, mock_subprocess):
509522        old_path  =  os .path .join (self .ext .templates_dirs (tpl )[0 ],
510523                                'evince.desktop' )
511524        with  open (old_path , 'wb' ) as  f :
512-             f .write (pkg_resources .resource_string (__name__ ,
513-                 'test-data/evince.desktop.template' ))
525+             evince_data  =  importlib .resources .files (
526+                 anchor = __name__ ).joinpath (
527+                 'test-data/evince.desktop.template' ).read_bytes ()
528+             f .write (evince_data )
514529        appvm  =  TestVM ('test-inst-app' ,
515530            klass = 'AppVM' ,
516531            template = tpl ,
@@ -536,10 +551,12 @@ def test_120_create_appvm(self, mock_subprocess):
536551        evince_path  =  self ._make_desktop_name (appvm , 'evince.desktop' )
537552        self .assertPathExists (evince_path )
538553        with  open (evince_path , 'rb' ) as  f :
554+             evince_data  =  importlib .resources .files (
555+                 anchor = __name__ ).joinpath (
556+                 'test-data/evince.desktop' ).read_bytes ()
539557            self .assertEqual (
540-                 pkg_resources .resource_string (__name__ ,
541-                     'test-data/evince.desktop' ).replace (b'%BASEDIR%' ,
542-                     qubesappmenus .basedir .encode ()),
558+                 evince_data .replace (b'%BASEDIR%' ,
559+                                     qubesappmenus .basedir .encode ()),
543560                f .read ()
544561            )
545562
@@ -583,8 +600,10 @@ def test_121_create_appvm_with_whitelist(self, mock_subprocess):
583600        self .ext .appmenus_init (tpl )
584601        with  open (os .path .join (self .ext .templates_dirs (tpl )[0 ],
585602                'evince.desktop' ), 'wb' ) as  f :
586-             f .write (pkg_resources .resource_string (__name__ ,
587-                 'test-data/evince.desktop.template' ))
603+             evince_data  =  importlib .resources .files (
604+                 anchor = __name__ ).joinpath (
605+                 'test-data/evince.desktop.template' ).read_bytes ()
606+             f .write (evince_data )
588607        with  open (os .path .join (self .basedir ,
589608                               tpl .name ,
590609                               'vm-whitelisted-appmenus.list' ), 'wb' ) as  f :
@@ -601,10 +620,12 @@ def test_121_create_appvm_with_whitelist(self, mock_subprocess):
601620        evince_path  =  self ._make_desktop_name (appvm , 'evince.desktop' )
602621        self .assertPathExists (evince_path )
603622        with  open (evince_path , 'rb' ) as  f :
623+             evince_data  =  importlib .resources .files (
624+                 anchor = __name__ ).joinpath (
625+                 'test-data/evince.desktop' ).read_bytes ()
604626            self .assertEqual (
605-                 pkg_resources .resource_string (__name__ ,
606-                     'test-data/evince.desktop' ).replace (b'%BASEDIR%' ,
607-                     qubesappmenus .basedir .encode ()),
627+                 evince_data .replace (b'%BASEDIR%' ,
628+                                     qubesappmenus .basedir .encode ()),
608629                f .read ()
609630            )
610631
@@ -666,9 +687,11 @@ class PopenMockup(object):
666687            'evince.desktop' )
667688        self .assertPathExists (evince_path )
668689        with  open (evince_path , 'rb' ) as  f :
690+             evince_data  =  importlib .resources .files (
691+                 anchor = __name__ ).joinpath (
692+                 'test-data/evince.desktop.template' ).read_bytes ()
669693            self .assertEqual (
670-                 pkg_resources .resource_string (__name__ ,
671-                     'test-data/evince.desktop.template' ),
694+                 evince_data ,
672695                f .read ()
673696            )
674697        self .assertCountEqual (self .appvm .log .mock_calls , [
0 commit comments