mitogen: Add initial support for importlib ResourceReader
The new classes are modelled closely on their existing Module* counterparts. For now I've duplicated the code, once it's bedded in I may refactor it. I didn't replicate the FORWARD_MODULE plumbing, it didn't seem to be necessary and may be dead code.pull/1403/head
parent
73f60a3123
commit
b7eddf2cdb
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
I'm a nested resource
|
||||
One layer down
|
||||
@ -0,0 +1,2 @@
|
||||
I'm a little resource
|
||||
Text, not source
|
||||
@ -0,0 +1,51 @@
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import testlib
|
||||
import resourced_pkg
|
||||
import resourced_pkg.sub_pkg
|
||||
|
||||
@unittest.skipIf(sys.version_info < (3, 7), 'importlib.resources, Python >= 3.7')
|
||||
class ResourceReaderBaselineTest(testlib.TestCase):
|
||||
'Assert out-the-box stdlib behaviours to cross validate remote tests.'
|
||||
def test_is_resource(self):
|
||||
import importlib.resources
|
||||
|
||||
self.assertFalse(importlib.resources.is_resource(resourced_pkg, 'does_not_exist'))
|
||||
self.assertFalse(importlib.resources.is_resource(resourced_pkg, 'sub_dir'))
|
||||
self.assertFalse(importlib.resources.is_resource(resourced_pkg.sub_pkg, 'does_not_exist'))
|
||||
|
||||
self.assertTrue(importlib.resources.is_resource(resourced_pkg, 'binary'))
|
||||
self.assertTrue(importlib.resources.is_resource(resourced_pkg, 'empty'))
|
||||
self.assertTrue(importlib.resources.is_resource(resourced_pkg, 'text.txt'))
|
||||
self.assertTrue(importlib.resources.is_resource(resourced_pkg, 'sub_dir/empty'))
|
||||
self.assertTrue(importlib.resources.is_resource(resourced_pkg.sub_pkg, 'text.txt'))
|
||||
|
||||
|
||||
@unittest.skipIf(sys.version_info < (3, 7), 'importlib.resources, Python >= 3.7')
|
||||
class ResourceReaderTest(testlib.RouterMixin, testlib.TestCase):
|
||||
def call_is_resource(self, conn):
|
||||
import importlib.resources
|
||||
|
||||
self.assertFalse(conn.call(importlib.resources.is_resource, 'resourced_pkg', 'does_not_exist'))
|
||||
self.assertFalse(conn.call(importlib.resources.is_resource, 'resourced_pkg', 'sub_dir'))
|
||||
self.assertFalse(conn.call(importlib.resources.is_resource, 'resourced_pkg.sub_pkg', 'does_not_exist'))
|
||||
|
||||
self.assertTrue(conn.call(importlib.resources.is_resource, 'resourced_pkg', 'binary'))
|
||||
self.assertTrue(conn.call(importlib.resources.is_resource, 'resourced_pkg', 'empty'))
|
||||
self.assertTrue(conn.call(importlib.resources.is_resource, 'resourced_pkg', 'text.txt'))
|
||||
self.assertTrue(conn.call(importlib.resources.is_resource, 'resourced_pkg', 'sub_dir/empty'))
|
||||
self.assertTrue(conn.call(importlib.resources.is_resource, 'resourced_pkg.sub_pkg', 'text.txt'))
|
||||
|
||||
def test_is_resource(self):
|
||||
# Uses the same version of Python so we can be sure importlib.resources is present
|
||||
# TODO Cross Python version tests
|
||||
connection = self.router.local(python_path=sys.executable)
|
||||
self.call_is_resource(conn=connection)
|
||||
|
||||
def test_is_resource_2_hops(self):
|
||||
# Uses the same version of Python so we can be sure importlib.resources is present
|
||||
# TODO Cross Python version tests
|
||||
hop_one = self.router.local(python_path=sys.executable)
|
||||
hop_two = self.router.local(python_path=sys.executable, via=hop_one)
|
||||
self.call_is_resource(conn=hop_two)
|
||||
Loading…
Reference in New Issue