コード例 #1
0
def test_resource_dir_invalid(tmpdir, monkeypatch):
    """test for nonexistent resource directory"""
    tmpdir = str(tmpdir)
    with monkeypatch.context() as m:
        m.setattr(resource, '_run_context', None, False)
        m.setattr(sys, 'frozen', True, False)
        m.setattr(sys, '_MEIPASS', tmpdir, False)
        rootdir = os.path.join(sys._MEIPASS, resource._BUNDLE_DIR)
        os.mkdir(rootdir)

        with pytest.raises(AssertionError):
            resource.get_resource_dir('test')
コード例 #2
0
def test_resource_dir_empty(tmpdir, monkeypatch):
    """test for empty resource directory"""
    tmpdir = str(tmpdir)
    with monkeypatch.context() as m:
        m.setattr(resource, '_run_context', None, False)
        m.setattr(sys, 'frozen', True, False)
        m.setattr(sys, '_MEIPASS', tmpdir, False)

        rootdir = os.path.join(sys._MEIPASS, resource._BUNDLE_DIR)
        os.mkdir(rootdir)

        test_dir = os.path.join(rootdir, "test")
        os.mkdir(test_dir)

        assert [] == resource.get_resource_dir('test')
コード例 #3
0
def test_resource_dir_package(resource_file, tmpdir, monkeypatch):
    """test for valid resource files in directory in package run context"""
    tmpdir = str(tmpdir)
    with monkeypatch.context() as m:
        test_dir = os.path.join(tmpdir, "test")
        os.mkdir(test_dir)

        m.setattr(pkg_resources, "resource_filename", lambda *args: os.path.join(tmpdir, test_dir))

        resfile = "test_{}.txt"

        res_test_files = [resfile.format(n + 1) for n in range(3)]

        m.setattr(pkg_resources, "resource_listdir", lambda *args: res_test_files)

        res_paths = [resource_file(test_dir, resfile.format(n + 1)) for n in range(3)]

        assert sorted(res_paths) == sorted(resource.get_resource_dir('test'))
コード例 #4
0
def test_resource_dir_bundle(resource_file, tmpdir, monkeypatch):
    """test for valid resource files in directory in standalone run context"""
    tmpdir = str(tmpdir)
    with monkeypatch.context() as m:
        m.setattr(resource, '_run_context', None, False)
        m.setattr(sys, 'frozen', True, False)
        m.setattr(sys, '_MEIPASS', tmpdir, False)

        rootdir = os.path.join(sys._MEIPASS, resource._BUNDLE_DIR)
        os.mkdir(rootdir)

        test_dir = os.path.join(rootdir, "test")
        os.mkdir(test_dir)

        resfile = "test_{}.txt"

        res_paths = [resource_file(test_dir, resfile.format(n + 1)) for n in range(3)]

        assert sorted(res_paths) == sorted(resource.get_resource_dir('test'))