Пример #1
0
 def test_build_plugin_file_path(self):
     current_dir = os.getcwd()
     src_plugin_dir = os.path.join(current_dir, 'plugins')
     ctx = Context(env=dict(PBT_PLUGINS_PATH=src_plugin_dir))
     path = ctx.path_to_plugin_file("new", "templates.json")
     #expected a path, but only check the last folders
     self.assertTrue("plugins/new/templates.json" in path)
Пример #2
0
    def test_load_null_project(self):
        log = FakeLogger()
        ctx = Context(log=log)
        path = os.path.join(TEST_DATA_DIR, "null_project",
                            ctx.project_descriptor_name)
        project = ctx.parse_project_descriptor(path)
        settings = project.settings

        self.assertEqual(project.organization, "no-organization")
        self.assertEqual(project.name, "no-name")
        self.assertEqual(project.version, "no-version")
        self.assertEqual(project.description, "No description")
        self.assertEqual(project.url, "No url")
        self.assertEqual(project.license, "No license")
        self.assertEqual(project.authors, [])
        self.assertEqual(project.dependencies, [])

        self.assertEqual(settings.min_version, "0.0.1")
        self.assertEqual(settings.plugins, [])
        self.assertEqual(settings.repositories, [])
        self.assertEqual(settings.plugin_repositories, [])
        self.assertEqual(settings.entry_point, ["no-name/main.py", "main"])
        self.assertEqual(settings.python_cmd, "python3")
        self.assertEqual(settings.python_opts, [])
        self.assertEqual(settings.packages, ["no-name"])
        self.assertEqual(settings.test_paths, ["test"])
        self.assertEqual(settings.resource_paths, ["resources"])
        self.assertEqual(settings.target_path, "target")
        self.assertEqual(settings.python_versions, [])
Пример #3
0
    def test_on_load_decorator_works(self):
        ctx = Context(env={})
        params = []

        @ctx.run_on_load
        def my_on_load(ctx, path):
            params.append((ctx, path))

        self.assertEqual(ctx.on_load_functions, [my_on_load])

        ctx.run_on_load_functions()
        self.assertEqual(params, [(ctx, os.path.abspath(__file__))])
Пример #4
0
    def test_load_project_fails_when_not_found(self):
        log = FakeLogger()
        ctx = Context(log=log)

        try:
            ctx.load_project("/foo/bar/")
            self.fail("this should raise an exception ProjectNotFoundError")
        except ProjectNotFoundError:
            pass

        self.assertEqual(log.debugs, ["Looking for '/foo/bar/project.pbt'",
                                      "Looking for '/foo/project.pbt'",
                                      "Looking for '/project.pbt'"])
Пример #5
0
    def test_load_project(self):
        log = FakeLogger()
        ctx = Context(log=log)
        path = os.path.join(TEST_DATA_DIR, ctx.project_descriptor_name)
        project = ctx.parse_project_descriptor(path)
        settings = project.settings

        self.assertEqual(project.organization, "pebete")
        self.assertEqual(project.name, "pbt")
        self.assertEqual(project.version, "0.0.1")
        self.assertEqual(project.description, "python build tool")
        self.assertEqual(project.url, "https://github.com/pebete/pbt")
        self.assertEqual(project.license, {
            "name": "Apache 2.0",
            "url": "http://opensource.org/licenses/Apache-2.0"
            })
        self.assertEqual(project.authors, [
            "Mariano Guerra <mariano@marianoguerra>", "x-ip", "joac", "L1pe"
            ])
        self.assertEqual(project.dependencies, [
            ["org.python", "requests", "2.0.0"]
            ])

        self.assertEqual(settings.min_version, "0.0.1")
        self.assertEqual(settings.plugins, [
            ["marianoguerra", "sphinx", "1.0.0"]
            ])
        self.assertEqual(settings.repositories, [
            ["pypi", "http:/pypi.python.org/"]
            ])
        self.assertEqual(settings.plugin_repositories, [
            ["pypi", "http:/pypi.python.org/"]
            ])
        self.assertEqual(settings.entry_point, ["src/pbt_cli.py", "run"])
        self.assertEqual(settings.python_cmd, "~/bin/pypy")
        self.assertEqual(settings.python_opts, ["-tt"])
        self.assertEqual(settings.packages, ["null"])
        self.assertEqual(settings.test_paths, ["test"])
        self.assertEqual(settings.resource_paths, ["resources"])
        self.assertEqual(settings.target_path, "target")
        self.assertEqual(settings.python_versions, ["2.6", "2.7", "3.3", "3.4",
                                                    ["pypy", "2.1"]])
Пример #6
0
    def test_fetch_plugin_file(self):
        ctx = Context()
        resulting_dirname = []
        resulting_url = []
        resulting_path = []

        def dummy_ensure_dir_exists(dirname):
            resulting_dirname.append(dirname)

        def dummy_fetch_resource(url, path):
            resulting_url.append(url)
            resulting_path.append(path)

        ctx.ensure_dir_exists = dummy_ensure_dir_exists
        ctx.fetch_resource = dummy_fetch_resource
        expected_path = ctx.path_to_plugin_file("new", "templates.json")
        expected_url = ctx.url_to_plugin_file("new", "templates.json")

        url, path = ctx.fetch_plugin_file("new", "templates.json")

        self.assertEqual(path, expected_path)
        self.assertEqual(url, expected_url)

        self.assertEqual(resulting_url[0], expected_url)
        self.assertEqual(resulting_path[0], expected_path)
        self.assertEqual(resulting_dirname[0], os.path.dirname(expected_path))
Пример #7
0
 def test_build_url_plugin_file_path(self):
     ctx = Context()
     url = ctx.url_to_plugin_file("new", "templates.json")
     expected = os.path.expanduser(ctx.registry_url + "new/templates.json")
     self.assertEqual(url, expected)