403Webshell
Server IP : 103.119.228.120  /  Your IP : 3.16.135.226
Web Server : Apache
System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : nobody ( 99)
PHP Version : 5.6.40
Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime
MySQL : ON |  cURL : ON |  WGET : ON |  Perl : ON |  Python : ON |  Sudo : ON |  Pkexec : ON
Directory :  /usr/lib/mysqlsh/lib/python3.9/site-packages/setuptools/tests/config/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/lib/mysqlsh/lib/python3.9/site-packages/setuptools/tests/config/test_expand.py
import os
import sys
from pathlib import Path

import pytest

from setuptools.config import expand
from setuptools.discovery import find_package_path

from distutils.errors import DistutilsOptionError


def write_files(files, root_dir):
    for file, content in files.items():
        path = root_dir / file
        path.parent.mkdir(exist_ok=True, parents=True)
        path.write_text(content, encoding="utf-8")


def test_glob_relative(tmp_path, monkeypatch):
    files = {
        "dir1/dir2/dir3/file1.txt",
        "dir1/dir2/file2.txt",
        "dir1/file3.txt",
        "a.ini",
        "b.ini",
        "dir1/c.ini",
        "dir1/dir2/a.ini",
    }

    write_files({k: "" for k in files}, tmp_path)
    patterns = ["**/*.txt", "[ab].*", "**/[ac].ini"]
    monkeypatch.chdir(tmp_path)
    assert set(expand.glob_relative(patterns)) == files
    # Make sure the same APIs work outside cwd
    assert set(expand.glob_relative(patterns, tmp_path)) == files


def test_read_files(tmp_path, monkeypatch):
    dir_ = tmp_path / "dir_"
    (tmp_path / "_dir").mkdir(exist_ok=True)
    (tmp_path / "a.txt").touch()
    files = {"a.txt": "a", "dir1/b.txt": "b", "dir1/dir2/c.txt": "c"}
    write_files(files, dir_)

    secrets = Path(str(dir_) + "secrets")
    secrets.mkdir(exist_ok=True)
    write_files({"secrets.txt": "secret keys"}, secrets)

    with monkeypatch.context() as m:
        m.chdir(dir_)
        assert expand.read_files(list(files)) == "a\nb\nc"

        cannot_access_msg = r"Cannot access '.*\.\..a\.txt'"
        with pytest.raises(DistutilsOptionError, match=cannot_access_msg):
            expand.read_files(["../a.txt"])

        cannot_access_secrets_msg = r"Cannot access '.*secrets\.txt'"
        with pytest.raises(DistutilsOptionError, match=cannot_access_secrets_msg):
            expand.read_files(["../dir_secrets/secrets.txt"])

    # Make sure the same APIs work outside cwd
    assert expand.read_files(list(files), dir_) == "a\nb\nc"
    with pytest.raises(DistutilsOptionError, match=cannot_access_msg):
        expand.read_files(["../a.txt"], dir_)


class TestReadAttr:
    @pytest.mark.parametrize(
        "example",
        [
            # No cookie means UTF-8:
            b"__version__ = '\xc3\xa9'\nraise SystemExit(1)\n",
            # If a cookie is present, honor it:
            b"# -*- coding: utf-8 -*-\n__version__ = '\xc3\xa9'\nraise SystemExit(1)\n",
            b"# -*- coding: latin1 -*-\n__version__ = '\xe9'\nraise SystemExit(1)\n",
        ],
    )
    def test_read_attr_encoding_cookie(self, example, tmp_path):
        (tmp_path / "mod.py").write_bytes(example)
        assert expand.read_attr('mod.__version__', root_dir=tmp_path) == 'é'

    def test_read_attr(self, tmp_path, monkeypatch):
        files = {
            "pkg/__init__.py": "",
            "pkg/sub/__init__.py": "VERSION = '0.1.1'",
            "pkg/sub/mod.py": (
                "VALUES = {'a': 0, 'b': {42}, 'c': (0, 1, 1)}\nraise SystemExit(1)"
            ),
        }
        write_files(files, tmp_path)

        with monkeypatch.context() as m:
            m.chdir(tmp_path)
            # Make sure it can read the attr statically without evaluating the module
            assert expand.read_attr('pkg.sub.VERSION') == '0.1.1'
            values = expand.read_attr('lib.mod.VALUES', {'lib': 'pkg/sub'})

        assert values['a'] == 0
        assert values['b'] == {42}

        # Make sure the same APIs work outside cwd
        assert expand.read_attr('pkg.sub.VERSION', root_dir=tmp_path) == '0.1.1'
        values = expand.read_attr('lib.mod.VALUES', {'lib': 'pkg/sub'}, tmp_path)
        assert values['c'] == (0, 1, 1)

    @pytest.mark.parametrize(
        "example",
        [
            "VERSION: str\nVERSION = '0.1.1'\nraise SystemExit(1)\n",
            "VERSION: str = '0.1.1'\nraise SystemExit(1)\n",
        ],
    )
    def test_read_annotated_attr(self, tmp_path, example):
        files = {
            "pkg/__init__.py": "",
            "pkg/sub/__init__.py": example,
        }
        write_files(files, tmp_path)
        # Make sure this attribute can be read statically
        assert expand.read_attr('pkg.sub.VERSION', root_dir=tmp_path) == '0.1.1'

    def test_import_order(self, tmp_path):
        """
        Sometimes the import machinery will import the parent package of a nested
        module, which triggers side-effects and might create problems (see issue #3176)

        ``read_attr`` should bypass these limitations by resolving modules statically
        (via ast.literal_eval).
        """
        files = {
            "src/pkg/__init__.py": "from .main import func\nfrom .about import version",
            "src/pkg/main.py": "import super_complicated_dep\ndef func(): return 42",
            "src/pkg/about.py": "version = '42'",
        }
        write_files(files, tmp_path)
        attr_desc = "pkg.about.version"
        package_dir = {"": "src"}
        # `import super_complicated_dep` should not run, otherwise the build fails
        assert expand.read_attr(attr_desc, package_dir, tmp_path) == "42"


@pytest.mark.parametrize(
    'package_dir, file, module, return_value',
    [
        ({"": "src"}, "src/pkg/main.py", "pkg.main", 42),
        ({"pkg": "lib"}, "lib/main.py", "pkg.main", 13),
        ({}, "single_module.py", "single_module", 70),
        ({}, "flat_layout/pkg.py", "flat_layout.pkg", 836),
    ],
)
def test_resolve_class(monkeypatch, tmp_path, package_dir, file, module, return_value):
    monkeypatch.setattr(sys, "modules", {})  # reproducibility
    files = {file: f"class Custom:\n    def testing(self): return {return_value}"}
    write_files(files, tmp_path)
    cls = expand.resolve_class(f"{module}.Custom", package_dir, tmp_path)
    assert cls().testing() == return_value


@pytest.mark.parametrize(
    'args, pkgs',
    [
        ({"where": ["."], "namespaces": False}, {"pkg", "other"}),
        ({"where": [".", "dir1"], "namespaces": False}, {"pkg", "other", "dir2"}),
        ({"namespaces": True}, {"pkg", "other", "dir1", "dir1.dir2"}),
        ({}, {"pkg", "other", "dir1", "dir1.dir2"}),  # default value for `namespaces`
    ],
)
def test_find_packages(tmp_path, args, pkgs):
    files = {
        "pkg/__init__.py",
        "other/__init__.py",
        "dir1/dir2/__init__.py",
    }
    write_files({k: "" for k in files}, tmp_path)

    package_dir = {}
    kwargs = {"root_dir": tmp_path, "fill_package_dir": package_dir, **args}
    where = kwargs.get("where", ["."])
    assert set(expand.find_packages(**kwargs)) == pkgs
    for pkg in pkgs:
        pkg_path = find_package_path(pkg, package_dir, tmp_path)
        assert os.path.exists(pkg_path)

    # Make sure the same APIs work outside cwd
    where = [
        str((tmp_path / p).resolve()).replace(os.sep, "/")  # ensure posix-style paths
        for p in args.pop("where", ["."])
    ]

    assert set(expand.find_packages(where=where, **args)) == pkgs


@pytest.mark.parametrize(
    "files, where, expected_package_dir",
    [
        (["pkg1/__init__.py", "pkg1/other.py"], ["."], {}),
        (["pkg1/__init__.py", "pkg2/__init__.py"], ["."], {}),
        (["src/pkg1/__init__.py", "src/pkg1/other.py"], ["src"], {"": "src"}),
        (["src/pkg1/__init__.py", "src/pkg2/__init__.py"], ["src"], {"": "src"}),
        (
            ["src1/pkg1/__init__.py", "src2/pkg2/__init__.py"],
            ["src1", "src2"],
            {"pkg1": "src1/pkg1", "pkg2": "src2/pkg2"},
        ),
        (
            ["src/pkg1/__init__.py", "pkg2/__init__.py"],
            ["src", "."],
            {"pkg1": "src/pkg1"},
        ),
    ],
)
def test_fill_package_dir(tmp_path, files, where, expected_package_dir):
    write_files({k: "" for k in files}, tmp_path)
    pkg_dir = {}
    kwargs = {"root_dir": tmp_path, "fill_package_dir": pkg_dir, "namespaces": False}
    pkgs = expand.find_packages(where=where, **kwargs)
    assert set(pkg_dir.items()) == set(expected_package_dir.items())
    for pkg in pkgs:
        pkg_path = find_package_path(pkg, pkg_dir, tmp_path)
        assert os.path.exists(pkg_path)

Youez - 2016 - github.com/yon3zu
LinuXploit