Пример #1
0
    def test_copy_into(self):
        # directory into directory
        source_d = testdata.create_files({
            "foo.txt": testdata.get_words(),
            "bar/che.txt": testdata.get_words(),
        })
        d = testdata.create_dir()
        d.copy_into(source_d)
        self.assertTrue("foo.txt" in d)
        self.assertTrue("bar/che.txt" in d)

        source_f = testdata.create_file("foo.txt", testdata.get_words())

        # file into directory
        d = testdata.create_dir()
        d.copy_into(source_f)
        self.assertTrue(source_f.basename in d)
        dest_f = d.get_file(source_f.basename)
        self.assertEqual(source_f.contents(), dest_f.contents())

        # file into file
        dest_f = testdata.create_file("foo.txt", testdata.get_words())
        self.assertNotEqual(source_f.contents(), dest_f.contents())
        dest_f.copy_into(source_f)
        self.assertEqual(source_f.contents(), dest_f.contents())
        self.assertTrue(source_f.contents() in dest_f.contents())
Пример #2
0
    def test_in_private(self):
        d = Directory(testdata.create_dir("/foo/_bar/che"))
        self.assertTrue(d.in_private())
        self.assertFalse(d.is_private())

        d = Directory(testdata.create_dir("/foo/_bar"))
        self.assertTrue(d.in_private())
        self.assertTrue(d.is_private())
Пример #3
0
    def test_existing_file_creation(self):
        path = testdata.create_dir()
        d2 = testdata.create_dir(path)
        self.assertEqual(path, d2)

        relpath = "/foo1/bar1/test.txt"
        s = "happy"
        f = testdata.create_file(relpath, s)
Пример #4
0
    def test__find_prefix_paths(self):
        modpath = testdata.create_module("find.prefix.paths.whew_test")
        pf = PathFinder(basedir=modpath.basedir)
        r = list(pf._find_prefix_paths(pf.basedir, "find.paths"))
        self.assertEqual(1, len(r))

        basedir = testdata.create_dir()
        other_basedir = testdata.create_dir("other/directory", basedir)
        other_modpath = testdata.create_module("tests.fpp_test", [], other_basedir)
        modpath = testdata.create_module("tests.fpp_test", [], basedir)

        pf = PathFinder(basedir=basedir)
        r = list(pf._find_prefix_paths(basedir, "tests"))
        self.assertEqual(2, len(r))
Пример #5
0
    def test_method_docblock_bad_decorator(self):
        tmpdir = testdata.create_dir("reflectdoc2")
        controller_prefix = "mdoc2"
        testdata.create_module(controller_prefix, [
            "import endpoints",
            "",
            "def bad_dec(func):",
            "    def wrapper(*args, **kwargs):",
            "        return func(*args, **kwargs)",
            "    return wrapper",
            "",
            "class Foo(endpoints.Controller):",
            "    '''controller docblock'''",
            "    @bad_dec",
            "    def GET(*args, **kwargs):",
            "        '''method docblock'''",
            "        pass",
            "",
            "    def POST(*args, **kwargs):",
            "        '''should not return this docblock'''",
            "        pass",
            "",
        ])

        rs = self.create_reflect(controller_prefix)
        for endpoint in rs:
            desc = endpoint.methods['GET'][0].desc
            self.assertEqual("method docblock", desc)
Пример #6
0
    def test_multi(self):
        # if there is an error in one of the tests but another test is found, don't
        # bubble up the error
        cwd = testdata.create_dir()
        testdata.create_modules(
            {
                "multi.bar_test": "\n".join(
                    ["from unittest import TestCase", "", "class BarTest(TestCase):", "    def test_bar(self): pass"]
                ),
                "multi.foo_test": "\n".join(
                    [
                        "from unittest import TestCase",
                        "",
                        "class FooTest(TestCase):",
                        "    def test_foo(self): pass",
                        "",
                        "class CheTest(TestCase):",
                        "    def test_che(self): pass",
                    ]
                ),
            },
            tmpdir=cwd,
        )

        ret_code = tester.run_test("multi.", cwd)
        self.assertEqual(0, ret_code)
Пример #7
0
    def test_method_docblock_bad_decorator(self):
        tmpdir = testdata.create_dir("reflectdoc2")
        controller_prefix = "mdoc2"
        testdata.create_module(controller_prefix, [
            "import endpoints",
            "",
            "def bad_dec(func):",
            "    def wrapper(*args, **kwargs):",
            "        return func(*args, **kwargs)",
            "    return wrapper",
            "",
            "class Foo(endpoints.Controller):",
            "    '''controller docblock'''",
            "    @bad_dec",
            "    def GET(*args, **kwargs):",
            "        '''method docblock'''",
            "        pass",
            "",
            "    def POST(*args, **kwargs):",
            "        '''should not return this docblock'''",
            "        pass",
            "",
        ])

        rs = self.create_reflect(controller_prefix)
        for endpoint in rs:
            desc = endpoint.methods['GET'][0].desc
            self.assertEqual("method docblock", desc)
Пример #8
0
    def test_get_endpoints(self):
        # putting the C back in CRUD
        tmpdir = testdata.create_dir("reflecttest")
        testdata.create_modules(
            {
                "controller_reflect": os.linesep.join([
                    "import endpoints",
                    "class Default(endpoints.Controller):",
                    "    def GET(*args, **kwargs): pass",
                    ""
                ]),
                "controller_reflect.foo": os.linesep.join([
                    "import endpoints",
                    "class Default(endpoints.Controller):",
                    "    def GET(*args, **kwargs): pass",
                    ""
                ]),
                "controller_reflect.che": os.linesep.join([
                    "from endpoints import Controller",
                    "class Baz(Controller):",
                    "    def POST(*args, **kwargs): pass",
                    ""
                ]),
                "controller_reflect.che.bam": os.linesep.join([
                    "from endpoints import Controller as Con",
                    "class _Base(Con):",
                    "    def GET(*args, **kwargs): pass",
                    "",
                    "class Boo(_Base):",
                    "    def DELETE(*args, **kwargs): pass",
                    "    def POST(*args, **kwargs): pass",
                    ""
                    "class Bah(_Base):",
                    "    '''this is the doc string'''",
                    "    def HEAD(*args, **kwargs): pass",
                    ""
                ])
            },
            tmpdir=tmpdir
        )

        r = endpoints.Reflect("controller_reflect")
        l = r.get_endpoints()
        self.assertEqual(5, len(l))

        def get_match(endpoint, l):
            for d in l:
                if d['endpoint'] == endpoint:
                    return d

        d = get_match("/che/bam/bah", l)
        self.assertEqual(d['options'], ["GET", "HEAD"])
        self.assertGreater(len(d['doc']), 0)

        d = get_match("/", l)
        self.assertNotEqual(d, {})

        d = get_match("/foo", l)
        self.assertNotEqual(d, {})
Пример #9
0
    def test_child(self):
        d = testdata.create_dir()
        d2 = d.child("foo", "bar")
        self.assertTrue(isinstance(d2, Dirpath))

        f = d.create_file("foo/bar.txt")
        f2 = d.child("foo/bar.txt")
        self.assertTrue(isinstance(f2, Filepath))
Пример #10
0
    def test_create_dir(self):
        ts = [
            "\\foo\\bar",
            "/foo1/bar1",
            "/foo2/bar2/",
            "foo3/bar3",
            "foo4/bar4/",
            "",
            None
        ]

        for t in ts:
            d = testdata.create_dir(t)
            self.assertTrue(os.path.isdir(d))

        with self.assertRaises(ValueError):
            testdata.create_dir("./foo/bar")
Пример #11
0
    def test_create_path(self):
        i = self.create_interface()
        config = i.connection_config

        d = testdata.create_dir()
        config.host = os.path.join(d, "create_path", "db.sqlite")

        i.connect(config)
        self.assertTrue(i.connected)
Пример #12
0
    def test_generate(self):
        project_dir = ProjectDirectory(testdata.create_dir())
        s = skeleton.Skeleton(project_dir)
        s.output()

        for file_dict in skeleton.file_skeleton:
            d = project_dir / file_dict['dir']
            self.assertTrue(d.exists())
            self.assertTrue(os.path.isfile(os.path.join(str(d), file_dict['basename'])))
Пример #13
0
    def test_issue_24(self):
        """Turns out I can't fix this issue, so this test is kind of useless"""
        # trying to setup the environment according to: https://github.com/Jaymon/pyt/issues/24
        raise self.skipTest("won't fix")
        basedir = testdata.create_dir()
        other_basedir = testdata.create_dir("other/directory", basedir)

        other_modpath = testdata.create_module(
            "i24tests.model24_test",
            [
                "from unittest import TestCase",
                "",
                "class Issue24TestCase(TestCase):",
                "   def test_boo(self):",
                "       pass",
            ],
            other_basedir
        )

        modpath = testdata.create_module(
            "i24tests.model24_test",
            [
                "from unittest import TestCase",
                "",
                "class Issue24TestCase(TestCase):",
                "   def test_boo(self):",
                "       pass",
            ],
            basedir
        )

        #pout.v(basedir, other_modpath.path, modpath.path)

        pf = PathFinder(
            basedir=basedir,
            module_name="model24",
            prefix="i24tests",
            class_name="Issue24",
            method_name="boo"
        )

        r = list(pf.method_names())
        self.assertEqual(2, len(r))
        self.assertNotEqual(r[0], r[1])
Пример #14
0
    def test_contents_decode_error(self):
        base_d = testdata.create_dir()
        os.chdir(base_d)
        f = base_d.create_file("bytes.txt", testdata.get_words())

        c = testdata.get_contents(f)
        self.assertTrue(isinstance(c, ContentBytes))

        c = testdata.get_contents(f, encoding="UTF-8")
        self.assertTrue(isinstance(c, ContentString))
Пример #15
0
    def test_create_file(self):
        ts = [
            "\\foo\\bar\\test.txt",
            "/foo1/bar1/test.txt",
            "/test.txt",
            "foo3/test.txt",
            "foo4/bar4/che4/test.txt",
        ]
        s = u"happy"

        for t in ts:
            f = testdata.create_file(t, s)
            self.assertTrue(os.path.isfile(f))
            with open(f) as fr:
                sr = fr.read()
                self.assertEqual(s, sr)

        with self.assertRaises(ValueError):
            testdata.create_dir("./foo/bar/test.txt")
Пример #16
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())
Пример #17
0
    def test_multi_table_backup(self):
        directory = testdata.create_dir("multi-table-backup")
        for x in range(10):
            f = Foo(bar=x)
            f.set()
            b = Bar(foo=x)
            b.set()

        c = Client("backup --dbname vagrant --username vagrant --password vagrant --dir {} foo bar".format(directory))
        pout.v(c.output)
Пример #18
0
    def get_dirs(cls, input_files):
        # TODO -- switch these to use the skeleton templates
        d = {
            'template/aux.html': "{{ aux.title }}\n{{ aux.html }}\n",
            'template/post.html': "{{ post.title }}\n{{ post.html }}\n{{ post.modified.strftime('%Y-%m-%d') }}\n",
            'template/posts.html': "\n".join([
                "{% for post in posts %}",
                "{% include 'post.html' %}",
                "<hr>",
                "{% endfor %}",
                "",
            ])
        }
        d.update(input_files)

        output_dir = Directory(testdata.create_dir())
        project_dir = Directory(testdata.create_dir())

        testdata.create_files(d, tmpdir=str(project_dir))
        return project_dir, output_dir
Пример #19
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)
Пример #20
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
Пример #21
0
    def test_relative_import(self):
        cwd = testdata.create_dir()
        testdata.create_modules(
            {
                "ritests": "from unittest import TestCase",
                "ritests.foo_test": "\n".join(
                    ["from . import TestCase", "", "class FooTest(TestCase):", "    def test_bar(self): pass"]
                ),
            },
            tmpdir=cwd,
        )

        ret_code = tester.run_test("Foo.bar", cwd)
Пример #22
0
    def test_create(self):
        d = testdata.create_dir()
        fex = testdata.create_file("create_exists", "foo", d)
        f = Filepath(fex)
        self.assertTrue(f.exists())
        f.create()
        self.assertTrue("foo" in f.lines())

        f = Filepath(d, "create_not_exists")
        self.assertFalse(f.exists())
        f.create()
        self.assertTrue(f.exists())
        self.assertFalse("foo" in f.lines())
Пример #23
0
    def test_bad_2(self):
        basedir = testdata.create_dir()
        em = self.get_email("bad-2")
        em.save(basedir)
        pout.v(basedir)

        email_dir = basedir.children[0].children[0]
        email_dir = basedir.first_dir().first_dir()
        email_dir = basedir.child_dir().child_dir()
        self.assertEqual(5, len(email_dir.files))


        pout.v(em.recipient_addrs)
Пример #24
0
    def test_save(self):
        basedir = testdata.create_dir()
        em = self.get_email("emoji-html-attachment")
        em.save(basedir)
        pout.v(basedir)

        em = self.get_email("cc")
        em.save(basedir)

        em = self.get_email("no-subject")
        em.save(basedir)

        em = self.get_email("simple-text")
        em.save(basedir)
Пример #25
0
    def test_dirpath_clear(self):
        d = testdata.create_dir()
        foo_f = d.create_file("foo.txt", "foo")
        bar_f = d.create_file("bar/bar.txt", "bar")
        che_d = d.create_dir("che")

        self.assertTrue(foo_f.exists())
        self.assertTrue(bar_f.exists())
        self.assertTrue(che_d.exists())

        d.clear()
        self.assertFalse(foo_f.exists())
        self.assertFalse(bar_f.exists())
        self.assertFalse(che_d.exists())
        self.assertEqual(0, len(list(d.files())))
Пример #26
0
    def test_no_tests_found(self):
        # if there is an error in one of the tests but another test is found, don't
        # bubble up the error
        cwd = testdata.create_dir()
        testdata.create_modules(
            {
                "nofound.nofo_test": "\n".join(
                    ["from unittest import TestCase", "", "class NofoTest(TestCase):", "    def test_nofo(self): pass"]
                )
            },
            tmpdir=cwd,
        )

        ret_code = tester.run_test("nofound_does_not_exist.", cwd)
        self.assertEqual(1, ret_code)
Пример #27
0
    def __init__(self):
        self.code = 0
        self.output = ""
        self.directory = testdata.create_dir()

        conn = Connection.get_instance()
        self.arg_str = " ".join([
            "--dbname={}".format(conn.dbname),
            "--username={}".format(conn.user),
            "--password={}".format(conn.password),
            "--host={}".format(conn.host),
            "--port={}".format(conn.port),
            "--dir={}".format(self.directory),
            "--debug",
        ])
Пример #28
0
    def test_copy_to(self):
        """https://github.com/Jaymon/testdata/issues/30"""
        source_d = testdata.create_files({
            "foo.txt": testdata.get_words(),
            "bar/che.txt": testdata.get_words(),
        })
        dest_d = testdata.create_dir()

        source_d.copy_to(dest_d)
        self.assertTrue("foo.txt" in dest_d)
        self.assertTrue("bar/che.txt" in dest_d)

        source_f = testdata.create_file("foo.txt", testdata.get_words())
        dest_f = testdata.get_file()
        self.assertFalse(dest_f.exists())
        source_f.copy_to(dest_f)
        self.assertEqual(source_f.contents(), dest_f.contents())
Пример #29
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
Пример #30
0
    def test_parse_error(self):
        cwd = testdata.create_dir()
        testdata.create_modules(
            {
                "tests_parse_error": "from unittest import TestCase",
                "tests_parse_error.pefoo_test": "\n".join(
                    [
                        "from . import TestCase",
                        "",
                        "class PEFooTest(TestCase):",
                        "    def test_bar(self):",
                        '        foo = "this is a parse error',
                    ]
                ),
            },
            tmpdir=cwd,
        )

        with self.assertRaises(SyntaxError):
            ret_code = tester.run_test("PEFoo.bar", cwd)
Пример #31
0
    def test_create_modules_4(self):
        """I discovered a bug while fixing some stuff in pyt where create_modules
        seems to create a structure like prefix/prefix/modname.py instead of 
        prefix/modname.py
        """
        basedir = testdata.create_dir()
        prefix = "testdata_cm4"
        r = testdata.create_modules({
            "foo": [
                "class Foo(object): pass",
            ],
            "bar": [
                "class Bar(object): pass",
            ],
        }, basedir, prefix=prefix)

        p = os.path.join(basedir, prefix)
        self.assertTrue(os.path.isdir(p))

        p2 = os.path.join(p, prefix)
        self.assertFalse(os.path.isdir(p2))
Пример #32
0
    def test_full_table_backup_and_restore(self):
        directory = testdata.create_dir("full-table-backup")
        #directory = os.path.join("/", "tmp", "full-table-backup-{}".format(random.randint(1, 100000)))
        for x in range(100):
            f = Foo(bar=x)
            f.set()

        c = Client("backup --dbname vagrant --username vagrant --password vagrant --dir {} foo".format(directory))
        path, dirs, files = os.walk(directory).next()
        self.assertEqual(1, len(files))

        c = Client("restore --dbname vagrant --username vagrant --password vagrant --dir {}".format(directory))
        self.assertEqual(100, Foo.query.count())

        f = Foo(bar=101)
        f.set()
        self.assertLess(100, f.pk)

        self.setUpClass()
        c = Client("restore --dbname vagrant --username vagrant --password vagrant --dir {}".format(directory))
        self.assertEqual(100, Foo.query.count())
Пример #33
0
    def __init__(self, *body, **kwargs):
        if len(body) == 1:
            body = body[0]

        self.body = body
        if not isinstance(body, basestring):
            self.body = "\n".join(body)

        self.cwd = testdata.create_dir()

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

        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]

        self.path = testdata.create_module(self.name, self.body, self.cwd)