Beispiel #1
0
    def test_path_is_package(self):
        m = testdata.create_package(contents="class Foo(object): pass")

        r = ReflectPath(m.directory)
        # we don't return the path because it isn't importable by name from the path we
        # passed in (itself), as of 7-4-2019 I think this is the correct behavior
        self.assertEqual(set(), r.module_names)
Beispiel #2
0
 def test_create_package(self):
     prefix = "foo"
     contents = os.linesep.join([
         "class Bar(object): pass",
     ])
     mp = testdata.create_package(prefix, contents=contents)
     self.assertTrue(mp.is_package())
Beispiel #3
0
    def test_has_shared_library(self):
        modpath = testdata.create_package(contents=[])
        shared_library = testdata.create_file("foo.so",
                                              tmpdir=modpath.directory)

        ps = Packages()
        p = ps[modpath]
        self.assertTrue(p.has_shared_library())
Beispiel #4
0
    def test_directory(self):
        d = testdata.create_dir()
        self.assertEqual(d, d.directory)

        f = testdata.create_file("dir.txt", "", d)
        self.assertEqual(d, f.directory)

        p = testdata.create_package("r.e", "", d)
        self.assertEqual(os.path.join(d, "r", "e"), p.directory)

        m = testdata.create_module("d.i", "", d)
        self.assertEqual(os.path.join(d, "d"), m.directory)
Beispiel #5
0
    def __init__(self, *body, **kwargs):
        if "cwd" in kwargs:
            self.cwd = kwargs["cwd"]
        else:
            self.cwd = testdata.create_dir()

        name = kwargs.get('name', None)
        if name is not None:
            self.name = name

        else:
            self.name = "prefix{}.pmod{}_test".format(
                testdata.get_ascii(5).lower(),
                testdata.get_ascii(5).lower()
            )

        self.module_name = ""
        self.prefix = ""
        self.name_prefix = ""
        if name:
            bits = self.name.rsplit('.', 1)
            self.module_name = bits[1] if len(bits) == 2 else bits[0]
            self.prefix = bits[0] if len(bits) == 2 else ''
            self.name_prefix = bits[1][:4] if len(bits) == 2 else bits[0][:4]

        if len(body) == 1: body = body[0]
        self.body = body
        if isinstance(self.body, dict):
            for k in self.body:
                self.body[k] = self._prepare_body(self.body[k])
            self.modules = testdata.create_modules(
                self.body,
                self.cwd,
                prefix=self.name,
            )
            self.path = self.modules.path

        else:
            if kwargs.get("package", False):
                self.module = testdata.create_package(
                    self.name,
                    self._prepare_body(self.body),
                    self.cwd
                )
            else:
                self.module = testdata.create_module(
                    self.name,
                    self._prepare_body(self.body),
                    self.cwd
                )

            self.path = self.module.path
Beispiel #6
0
    def test_routing_package(self):
        controller_prefix = "routepack"
        contents = [
            "from endpoints import Controller",
            "",
            "class Default(Controller):",
            "    def GET(self): pass",
            "",
        ]
        f = testdata.create_package(controller_prefix, contents=contents)

        r = ReflectModule(controller_prefix)
        self.assertTrue(controller_prefix in r.module_names)
        self.assertEqual(1, len(r.module_names))
    def test_routing_package(self):
        controller_prefix = "routepack"
        contents = [
            "from endpoints import Controller",
            "",
            "class Default(Controller):",
            "    def GET(self): pass",
            "",
        ]
        f = testdata.create_package(controller_prefix, contents=contents)

        r = ReflectModule(controller_prefix)
        self.assertTrue(controller_prefix in r.module_names)
        self.assertEqual(1, len(r.module_names))
Beispiel #8
0
    def test_package(self):
        m = testdata.create_package(
            "foo_test",
            [
                "from __future__ import print_function",
                "from unittest import TestCase",
                "class FooTest(TestCase):",
                "    def test_foo(self):",
                "        print('in foo test')",
                "",
            ],
        )

        s = Client(m.basedir)
        r = s.run("foo_test")
        self.assertTrue("in foo test" in r)
Beispiel #9
0
    def __init__(self, *body, **kwargs):
        if "cwd" in kwargs:
            self.cwd = kwargs["cwd"]
        else:
            self.cwd = testdata.create_dir()

        name = kwargs.get('name', None)
        if name is not None:
            self.name = name

        else:
            self.name = "prefix{}.pmod{}_test".format(
                testdata.get_ascii(5).lower(),
                testdata.get_ascii(5).lower())

        self.module_name = ""
        self.prefix = ""
        self.name_prefix = ""
        if self.name:
            bits = self.name.rsplit('.', 1)
            self.module_name = bits[1] if len(bits) == 2 else bits[0]
            self.prefix = bits[0] if len(bits) == 2 else ''
            self.name_prefix = bits[1][:4] if len(bits) == 2 else bits[0][:4]

        if len(body) == 1: body = body[0]
        self.body = body
        if isinstance(self.body, dict):
            for k in self.body:
                self.body[k] = self._prepare_body(self.body[k])
            self.modules = testdata.create_modules(
                self.body,
                self.cwd,
                prefix=self.name,
            )
            self.path = self.modules.path

        else:
            if kwargs.get("package", False):
                self.module = testdata.create_package(
                    self.name, self._prepare_body(self.body), self.cwd)
            else:
                self.module = testdata.create_module(
                    self.name, self._prepare_body(self.body), self.cwd)

            self.path = self.module.path
Beispiel #10
0
    def test_create_package(self):
        prefix = "foo"
        contents = os.linesep.join([
            "class Bar(object): pass",
        ])
        mp = testdata.create_package(prefix, contents=contents)
        self.assertTrue(mp.is_package())
        return



        basedir = testdata.create_dir()
        prefix = "foo"
        testdata.create_dir(prefix, tmpdir=basedir)
        contents = os.linesep.join([
            "class Bar(object): pass",
        ])
        mp = testdata.create_module(prefix, contents=contents, tmpdir=basedir)
        self.assertTrue(mp.is_package())