示例#1
0
    def test_Resources_scan(self):
        fpath = os.path.join(os.path.dirname(__file__))
        res = resources.Resources()
        res.scan(fpath)
        self.assertIsNotNone(res.get("rwopstest.txt"))
        self.assertIsNotNone(res.get("surfacetest.bmp"))

        self.assertRaises(ValueError, res.scan, "invalid")
        self.assertRaises(ValueError, res.scan, fpath, "invalid")
        self.assertRaises(Exception, res.scan, 12345)

        res = resources.Resources()
        res.scan(fpath, "resources")
        self.assertIsNotNone(res.get("rwopstest.txt"))
        self.assertIsNotNone(res.get("surfacetest.bmp"))
    def test_Resources_scan(self):
        fpath = os.path.join(os.path.dirname(__file__))
        res = resources.Resources()
        res.scan(fpath)
        assert res.get("rwopstest.txt") is not None
        assert res.get("surfacetest.bmp") is not None

        with pytest.raises(ValueError):
            res.scan("invalid")
        with pytest.raises(ValueError):
            res.scan(fpath, "invalid")
        with pytest.raises(Exception):
            res.scan(12345)

        res = resources.Resources()
        res.scan(fpath, "resources")
        assert res.get("rwopstest.txt") is not None
        assert res.get("surfacetest.bmp") is not None
示例#3
0
    def test_Resources(self):
        self.assertRaises(ValueError, resources.Resources, "invalid")

        res = resources.Resources()
        self.assertIsInstance(res, resources.Resources)
        self.assertRaises(KeyError, res.get, "surfacetest.bmp")

        fpath = os.path.join(os.path.dirname(__file__), "resources")
        res = resources.Resources(fpath)
        self.assertIsNotNone(res.get("rwopstest.txt"))
        self.assertIsNotNone(res.get("surfacetest.bmp"))

        res2 = resources.Resources(__file__)
        self.assertIsNotNone(res2.get("rwopstest.txt"))
        self.assertIsNotNone(res2.get("surfacetest.bmp"))

        res3 = resources.Resources(__file__, "resources")
        self.assertIsNotNone(res3.get("rwopstest.txt"))
        self.assertIsNotNone(res3.get("surfacetest.bmp"))
示例#4
0
    def test_Resources_add_archive(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        zfile = os.path.join(fpath, "resources.zip")
        tfile = os.path.join(fpath, "resources.tar.gz")

        res = resources.Resources()
        res.add_archive(zfile)

        self.assertIsNotNone(res.get("surfacetest.bmp"))
        self.assertIsNotNone(res.get("rwopstest.txt"))
        self.assertRaises(KeyError, res.get, "resources.zip")

        self.assertRaises(TypeError, res.add_archive, None)
        self.assertRaises(ValueError, res.add_archive, "invalid_name.txt")

        res = resources.Resources()
        res.add_archive(tfile, typehint="targz")
        self.assertIsNotNone(res.get("surfacetest.bmp"))
        self.assertIsNotNone(res.get("rwopstest.txt"))
        self.assertRaises(KeyError, res.get, "resources.tar.gz")
    def test_Resources(self):
        with pytest.raises(ValueError):
            resources.Resources("invalid")

        res = resources.Resources()
        assert isinstance(res, resources.Resources)
        with pytest.raises(KeyError):
            res.get("surfacetest.bmp")

        fpath = os.path.join(os.path.dirname(__file__), "resources")
        res = resources.Resources(fpath)
        assert res.get("rwopstest.txt") is not None
        assert res.get("surfacetest.bmp") is not None

        res2 = resources.Resources(__file__)
        assert res2.get("rwopstest.txt") is not None
        assert res2.get("surfacetest.bmp") is not None

        res3 = resources.Resources(__file__, "resources")
        assert res3.get("rwopstest.txt") is not None
        assert res3.get("surfacetest.bmp") is not None
示例#6
0
    def test_Resources_get(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")

        for path in (fpath, None):
            res = resources.Resources(path)

            self.assertRaises(KeyError, res.get, "invalid_file.txt")
            self.assertRaises(KeyError, res.get, None)
            self.assertRaises(KeyError, res.get, 123456)
            if path is None:
                self.assertRaises(KeyError, res.get, "surfacetest.bmp")
                self.assertRaises(KeyError, res.get, "rwopstest.txt")
            else:
                self.assertIsNotNone(res.get("surfacetest.bmp"))
                self.assertIsNotNone(res.get("rwopstest.txt"))
    def test_Resources_add_archive(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        zfile = os.path.join(fpath, "resources.zip")
        tfile = os.path.join(fpath, "resources.tar.gz")

        res = resources.Resources()
        res.add_archive(zfile)

        assert res.get("surfacetest.bmp") is not None
        assert res.get("rwopstest.txt") is not None
        with pytest.raises(KeyError):
            res.get("resources.zip")

        with pytest.raises(TypeError):
            res.add_archive(None)
        with pytest.raises(ValueError):
            res.add_archive("invalid_name.txt")

        res = resources.Resources()
        res.add_archive(tfile, typehint="targz")
        assert res.get("surfacetest.bmp") is not None
        assert res.get("rwopstest.txt") is not None
        with pytest.raises(KeyError):
            res.get("resources.tar.gz")
示例#8
0
    def test_Resources_add(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        sfile = os.path.join(fpath, "surfacetest.bmp")
        zfile = os.path.join(fpath, "resources.zip")

        res = resources.Resources()
        res.add(sfile)
        self.assertRaises(KeyError, res.get, "rwopstest.txt")
        self.assertIsNotNone(res.get("surfacetest.bmp"))

        res.add(zfile)
        self.assertIsNotNone(res.get("rwopstest.txt"))
        self.assertIsNotNone(res.get("surfacetest.bmp"))

        self.assertRaises(TypeError, res.add, None)
        self.assertRaises(ValueError, res.add, "invalid_name.txt")
示例#9
0
    def test_Resources_get_path(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        zfile = os.path.join(fpath, "resources.zip")
        pfile = os.path.join(fpath, "rwopstest.txt")

        res = resources.Resources()
        res.add(zfile)
        res.add(pfile)

        zpath = res.get_path("surfacetest.bmp")
        self.assertTrue(zpath.find("surfacetest.bmp@") != -1)
        self.assertNotEqual(zpath, zfile)
        ppath = res.get_path("rwopstest.txt")
        self.assertTrue(ppath.find("rwopstest.txt") != -1)

        self.assertRaises(KeyError, res.get_path, None)
        self.assertRaises(KeyError, res.get_path, "invalid")
        self.assertRaises(KeyError, res.get_path, 1234)
    def test_Resources_add(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        sfile = os.path.join(fpath, "surfacetest.bmp")
        zfile = os.path.join(fpath, "resources.zip")

        res = resources.Resources()
        res.add(sfile)
        with pytest.raises(KeyError):
            res.get("rwopstest.txt")
        assert res.get("surfacetest.bmp") is not None

        res.add(zfile)
        assert res.get("rwopstest.txt") is not None
        assert res.get("surfacetest.bmp") is not None

        with pytest.raises(TypeError):
            res.add(None)
        with pytest.raises(ValueError):
            res.add("invalid_name.txt")
    def test_Resources_get(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")

        for path in (fpath, None):
            res = resources.Resources(path)

            with pytest.raises(KeyError):
                res.get("invalid_file.txt")
            with pytest.raises(KeyError):
                res.get(None)
            with pytest.raises(KeyError):
                res.get(123456)
            if path is None:
                with pytest.raises(KeyError):
                    res.get("surfacetest.bmp")
                with pytest.raises(KeyError):
                    res.get("rwopstest.txt")
            else:
                assert res.get("surfacetest.bmp") is not None
                assert res.get("rwopstest.txt") is not None
示例#12
0
    def test_Resources_get_filelike(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        zfile = os.path.join(fpath, "resources.zip")
        pfile = os.path.join(fpath, "rwopstest.txt")

        res = resources.Resources()
        res.add(zfile)

        v1 = res.get_filelike("rwopstest.txt")
        v2 = res.get_filelike("surfacetest.bmp")
        self.assertEqual(type(v1), type(v2))

        res.add(pfile)

        v1 = res.get_filelike("rwopstest.txt")
        v2 = res.get_filelike("surfacetest.bmp")
        self.assertNotEqual(type(v1), type(v2))

        self.assertRaises(KeyError, res.get_filelike, None)
        self.assertRaises(KeyError, res.get_filelike, "invalid")
        self.assertRaises(KeyError, res.get_filelike, 1234)
    def test_Resources_get_path(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        zfile = os.path.join(fpath, "resources.zip")
        pfile = os.path.join(fpath, "rwopstest.txt")

        res = resources.Resources()
        res.add(zfile)
        res.add(pfile)

        zpath = res.get_path("surfacetest.bmp")
        assert zpath.find("surfacetest.bmp@") != -1
        assert zpath != zfile
        ppath = res.get_path("rwopstest.txt")
        assert ppath.find("rwopstest.txt") != -1

        with pytest.raises(KeyError):
            res.get_path(None)
        with pytest.raises(KeyError):
            res.get_path("invalid")
        with pytest.raises(KeyError):
            res.get_path(1234)
    def test_Resources_get_filelike(self):
        fpath = os.path.join(os.path.dirname(__file__), "resources")
        zfile = os.path.join(fpath, "resources.zip")
        pfile = os.path.join(fpath, "rwopstest.txt")

        res = resources.Resources()
        res.add(zfile)

        v1 = res.get_filelike("rwopstest.txt")
        v2 = res.get_filelike("surfacetest.bmp")
        assert type(v1) == type(v2)

        res.add(pfile)

        v1 = res.get_filelike("rwopstest.txt")
        v2 = res.get_filelike("surfacetest.bmp")
        assert type(v1) != type(v2)

        with pytest.raises(KeyError):
            res.get_filelike(None)
        with pytest.raises(KeyError):
            res.get_filelike("invalid")
        with pytest.raises(KeyError):
            res.get_filelike(1234)