【pytest系列】- parametrize参数化

news2024/11/16 1:57:50

 🔥 交流讨论:欢迎加入我们一起学习!

🔥 资源分享耗时200+小时精选的「软件测试」资料包

🔥 教程推荐:火遍全网的《软件测试》教程  

📢欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请指正!

前面已经提到,pytest和unittest是兼容的,但是它也有不兼容的地方,比如ddt数据驱动,测试夹具fixtures(即setup、teardown)这些功能在pytest中都不能使用了,因为pytest已经不再继承unittest了。

​ 不使用ddt数据驱动那pytest是如何实现参数化的呢?答案就是mark里自带的一个参数化标签。

源码解读

​ 关键代码:@pytest.mark.parametrize

​ 我们先看下源码:def parametrize(self,argnames, argvalues, indirect=False, ids=None, scope=None):,按住ctrl然后点击对应的函数名就可查看源码。

python
<span style="background-color:#282c34"><span style="color:#abb2bf">    <span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">parametrize</span>(<span style="color:#a6e22e">self,argnames, argvalues, indirect=<span style="color:#56b6c2">False</span>, ids=<span style="color:#56b6c2">None</span>, scope=<span style="color:#56b6c2">None</span></span>):</span>
        <span style="color:#98c379">""" Add new invocations to the underlying test function using the list
        of argvalues for the given argnames.  Parametrization is performed
        during the collection phase.  If you need to setup expensive resources
        see about setting indirect to do it rather at test setup time.

        :arg argnames: a comma-separated string denoting one or more argument
                       names, or a list/tuple of argument strings.

        :arg argvalues: The list of argvalues determines how often a
            test is invoked with different argument values.  If only one
            argname was specified argvalues is a list of values.  If N
            argnames were specified, argvalues must be a list of N-tuples,
            where each tuple-element specifies a value for its respective
            argname.

        :arg indirect: The list of argnames or boolean. A list of arguments'
            names (self,subset of argnames). If True the list contains all names from
            the argnames. Each argvalue corresponding to an argname in this list will
            be passed as request.param to its respective argname fixture
            function so that it can perform more expensive setups during the
            setup phase of a test rather than at collection time.

        :arg ids: list of string ids, or a callable.
            If strings, each is corresponding to the argvalues so that they are
            part of the test id. If None is given as id of specific test, the
            automatically generated id for that argument will be used.
            If callable, it should take one argument (self,a single argvalue) and return
            a string or return None. If None, the automatically generated id for that
            argument will be used.
            If no ids are provided they will be generated automatically from
            the argvalues.

        :arg scope: if specified it denotes the scope of the parameters.
            The scope is used for grouping tests by parameter instances.
            It will also override any fixture-function defined scope, allowing
            to set a dynamic scope using test context or configuration.
        """</span>
</span></span>

​ 我们来看下主要的四个参数:

​ 🍊参数1-argnames:一个或多个参数名,用逗号分隔的字符串,如"arg1,arg2,arg3",或参数字符串的列表/元组。需要注意的是,参数名需要与用例的入参一致

​ 🍊参数2-argvalues:参数值,必须是列表类型;如果有多个参数,则用元组存放值,一个元组存放一组参数值,元组放在列表。(实际上元组包含列表、列表包含列表也是可以的,可以动手试一下)

python
<span style="background-color:#282c34"><span style="color:#abb2bf"><span style="color:#b18eb1"><em># 只有一个参数username时,列表里都是这个参数的值:</em></span>
<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">"username"</span>, [<span style="color:#3388aa">"user1"</span>, <span style="color:#3388aa">"user2"</span>, <span style="color:#3388aa">"user3"</span>])</span>
<span style="color:#b18eb1"><em># 有多个参数username、pwd,用元组存放参数值,一个元组对应一组参数:</em></span>
<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">"username, pwd"</span>, [(<span style="color:#3388aa">"user1"</span>, <span style="color:#3388aa">"pwd1"</span>), (<span style="color:#3388aa">"user2"</span>, <span style="color:#3388aa">"pwd2"</span>), (<span style="color:#3388aa">"user3"</span>, <span style="color:#3388aa">"pwd3"</span>)])</span></span></span>

​ 🍊参数3-indirect:默认为False,设置为Ture时会把传进来的参数(argnames)当函数执行。后面会进行详解。

​ 🍊参数4-ids:用例的ID,传字符串列表,它可以标识每一个测试用例,自定义测试数据结果显示,增加可读性;需要注意的是ids的长度需要与测试用例的数量一致。

单个参数化

​ 下面我们来看下常用的参数化:

python
<span style="background-color:#282c34"><span style="color:#abb2bf"><span style="color:#f92672">import</span> pytest


data = [(<span style="color:#d19a66">1</span>, <span style="color:#d19a66">2</span>, <span style="color:#d19a66">3</span>), (<span style="color:#d19a66">4</span>, <span style="color:#d19a66">5</span>, <span style="color:#d19a66">9</span>)]


<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">'a, b, expect'</span>, data)</span>
<span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">test_param</span>(<span style="color:#a6e22e">a, b, expect</span>):</span>
    <span style="color:#e6c07b">print</span>(<span style="color:#98c379">'\n测试数据:{}+{}'</span>.<span style="color:#e6c07b">format</span>(a, b))
    <span style="color:#f92672">assert</span> a+b == expect</span></span>

​ 运行结果:

shell
<span style="background-color:#282c34"><span style="color:#abb2bf">Testing started at 14:10 ...

============================= test session starts =============================
platform win32 -- Python 3.8.1, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- C:\software\python\python.exe
cachedir: .pytest_cache
rootdir: D:\myworkspace\test, inifile: pytest.ini
collecting ... test.py::test_param[1-2-3]
test.py::test_param[4-5-9]
collected 2 items

test.py::test_param[1-2-3] PASSED                                        [ 50%]
测试数据:1+2

test.py::test_param[4-5-9] PASSED                                        [100%]
测试数据:4+5


============================== 2 passed in 0.02s ==============================

Process finished with exit code 0</span></span>

​ 如上用例参数化后,一条测试数据就会执行一遍用例。

​ 再看下列表包含字典的:

python
<span style="background-color:#282c34"><span style="color:#abb2bf"><span style="color:#f92672">import</span> pytest


<span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">login</span>(<span style="color:#a6e22e">user, pwd</span>):</span>
    <span style="color:#98c379">"""登录功"""</span>
    <span style="color:#f92672">if</span> user == <span style="color:#98c379">"admin"</span> <span style="color:#f92672">and</span> pwd == <span style="color:#98c379">"admin123"</span>:
        <span style="color:#f92672">return</span> {<span style="color:#98c379">"code"</span>: <span style="color:#d19a66">0</span>, <span style="color:#98c379">"msg"</span>: <span style="color:#98c379">"登录成功!"</span>}
    <span style="color:#f92672">else</span>:
        <span style="color:#f92672">return</span> {<span style="color:#98c379">"code"</span>: <span style="color:#d19a66">1</span>, <span style="color:#98c379">"msg"</span>: <span style="color:#98c379">"登陆失败,账号或密码错误!"</span>}


<span style="color:#b18eb1"><em># 测试数据</em></span>
test_datas = [{<span style="color:#98c379">"user"</span>: <span style="color:#98c379">"admin"</span>, <span style="color:#98c379">"pwd"</span>: <span style="color:#98c379">"admin123"</span>, <span style="color:#98c379">"expected"</span>: <span style="color:#98c379">"登录成功!"</span>},
              {<span style="color:#98c379">"user"</span>: <span style="color:#98c379">""</span>, <span style="color:#98c379">"pwd"</span>: <span style="color:#98c379">"admin123"</span>, <span style="color:#98c379">"expected"</span>: <span style="color:#98c379">"登陆失败,账号或密码错误!"</span>},
              {<span style="color:#98c379">"user"</span>: <span style="color:#98c379">"admin"</span>, <span style="color:#98c379">"pwd"</span>: <span style="color:#98c379">""</span>, <span style="color:#98c379">"expected"</span>: <span style="color:#98c379">"登陆失败,账号或密码错误!"</span>}
              ]


<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">"test_data"</span>, test_datas)</span>
<span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">test_login</span>(<span style="color:#a6e22e">test_data</span>):</span>
    <span style="color:#b18eb1"><em># 测试用例</em></span>
    res = login(test_data[<span style="color:#98c379">"user"</span>], test_data[<span style="color:#98c379">"pwd"</span>])
    <span style="color:#b18eb1"><em># 断言</em></span>
    <span style="color:#e6c07b">print</span>(<span style="color:#d19a66">111</span>)
    <span style="color:#f92672">assert</span> res[<span style="color:#98c379">"msg"</span>] == test_data[<span style="color:#98c379">"expected"</span>]</span></span>

​ 运行结果:

shell
<span style="background-color:#282c34"><span style="color:#abb2bf">Testing started at 14:13 ...

============================= test session starts =============================
platform win32 -- Python 3.8.1, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- C:\software\python\python.exe
cachedir: .pytest_cache
rootdir: D:\myworkspace\test, inifile: pytest.ini
collecting ... test.py::test_login[test_data0]
test.py::test_login[test_data1]
test.py::test_login[test_data2]
collected 3 items

test.py::test_login[test_data0] PASSED                                   [ 33%]111

test.py::test_login[test_data1] PASSED                                   [ 66%]111

test.py::test_login[test_data2] PASSED                                   [100%]111


============================== 3 passed in 0.02s ==============================

Process finished with exit code 0</span></span>

多个参数化

​ 一个函数或一个类都可以使用多个参数化装饰器,“笛卡尔积”原理。最终生成的用例是n1*n2*n3...条,如下例子,参数一的值有2个,参数二的值有3个,那么最后生成的用例就是2*3条。

python
<span style="background-color:#282c34"><span style="color:#abb2bf"><span style="color:#f92672">import</span> pytest


data1 = [<span style="color:#d19a66">1</span>, <span style="color:#d19a66">2</span>]
data2 = [<span style="color:#98c379">'a'</span>, <span style="color:#98c379">'b'</span>, <span style="color:#98c379">'c'</span>]


<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">'test1'</span>, data1)</span>
<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">'test2'</span>, data2)</span>
<span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">test_param</span>(<span style="color:#a6e22e">test1, test2</span>):</span>
    <span style="color:#e6c07b">print</span>(<span style="color:#98c379">'\n测试数据:{}-{}'</span>.<span style="color:#e6c07b">format</span>(test1, test2))</span></span>

​ 运行结果:

shell
<span style="background-color:#282c34"><span style="color:#abb2bf">Testing started at 14:15 ...

============================= test session starts =============================
platform win32 -- Python 3.8.1, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- C:\software\python\python.exe
cachedir: .pytest_cache
rootdir: D:\myworkspace\test, inifile: pytest.ini
collecting ... test.py::test_param[a-1]
test.py::test_param[a-2]
test.py::test_param[b-1]
test.py::test_param[b-2]
test.py::test_param[c-1]
test.py::test_param[c-2]
collected 6 items

test.py::test_param[a-1] PASSED                                          [ 16%]
测试数据:1-a

test.py::test_param[a-2] PASSED                                          [ 33%]
测试数据:2-a

test.py::test_param[b-1] PASSED                                          [ 50%]
测试数据:1-b

test.py::test_param[b-2] PASSED                                          [ 66%]
测试数据:2-b

test.py::test_param[c-1] PASSED                                          [ 83%]
测试数据:1-c

test.py::test_param[c-2] PASSED                                          [100%]
测试数据:2-c


============================== 6 passed in 0.03s ==============================

Process finished with exit code 0</span></span>

​ 从上面的例子来看,@pytest.mark.parametrize()其实跟ddt的用法很相似的,多用就好了。

标记数据

​ 在参数化中,也可以标记数据进行断言、跳过等

python
<span style="background-color:#282c34"><span style="color:#abb2bf"><span style="color:#b18eb1"><em># 标记参数化</em></span>
<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">"test_input,expected"</span>, [
    (<span style="color:#3388aa">"3+5"</span>, <span style="color:#d19a66">8</span>), (<span style="color:#3388aa">"2+4"</span>, <span style="color:#d19a66">6</span>),
    pytest.param(<span style="color:#3388aa">"6 * 9"</span>, <span style="color:#d19a66">42</span>, marks=pytest.mark.xfail),
    pytest.param(<span style="color:#3388aa">"6 * 6"</span>, <span style="color:#d19a66">42</span>, marks=pytest.mark.skip)
])</span>
<span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">test_mark</span>(<span style="color:#a6e22e">test_input, expected</span>):</span>
    <span style="color:#f92672">assert</span> <span style="color:#e6c07b">eval</span>(test_input) == expected</span></span>

​ 运行结果,可以看到2个通过,1个断言失败的,1个跳过的。

shell
<span style="background-color:#282c34"><span style="color:#abb2bf">Testing started at 14:17 ...

============================= test session starts =============================
platform win32 -- Python 3.8.1, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- C:\software\python\python.exe
cachedir: .pytest_cache
rootdir: D:\myworkspace\test, inifile: pytest.ini
collecting ... test.py::test_mark[3+5-8]
test.py::test_mark[2+4-6]
test.py::test_mark[6 * 9-42]
test.py::test_mark[6 * 6-42]
collected 4 items

test.py::test_mark[3+5-8] 
test.py::test_mark[2+4-6] 
test.py::test_mark[6 * 9-42] 
test.py::test_mark[6 * 6-42] 

=================== 2 passed, 1 skipped, 1 xfailed in 0.14s ===================

Process finished with exit code 0
PASSED                                         [ 25%]PASSED                                         [ 50%]XFAIL                                       [ 75%]
test_input = '6 * 9', expected = 42

    @pytest.mark.parametrize("test_input,expected", [
        ("3+5", 8), ("2+4", 6),
        pytest.param("6 * 9", 42, marks=pytest.mark.xfail),
        pytest.param("6 * 6", 42, marks=pytest.mark.skip)
    ])
    def test_mark(test_input, expected):
<span style="color:#61aeee">></span>       assert <span style="color:#e6c07b">eval</span>(test_input) == expected
E       AssertionError

test.py:89: AssertionError
SKIPPED                                     [100%]
Skipped: unconditional skip</span></span>

用例ID

​ 前面源码分析说到ids可以标识每一个测试用例;有多少组数据,就要有多少个id,然后组成一个id的列表;现在来看下实例。

python
<span style="background-color:#282c34"><span style="color:#abb2bf"><span style="color:#f92672">import</span> pytest


<span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">login</span>(<span style="color:#a6e22e">user, pwd</span>):</span>
    <span style="color:#98c379">"""登录功"""</span>
    <span style="color:#f92672">if</span> user == <span style="color:#98c379">"admin"</span> <span style="color:#f92672">and</span> pwd == <span style="color:#98c379">"admin123"</span>:
        <span style="color:#f92672">return</span> {<span style="color:#98c379">"code"</span>: <span style="color:#d19a66">0</span>, <span style="color:#98c379">"msg"</span>: <span style="color:#98c379">"登录成功!"</span>}
    <span style="color:#f92672">else</span>:
        <span style="color:#f92672">return</span> {<span style="color:#98c379">"code"</span>: <span style="color:#d19a66">1</span>, <span style="color:#98c379">"msg"</span>: <span style="color:#98c379">"登陆失败,账号或密码错误!"</span>}


<span style="color:#b18eb1"><em># 测试数据</em></span>
test_datas = [{<span style="color:#98c379">"user"</span>: <span style="color:#98c379">"admin"</span>, <span style="color:#98c379">"pwd"</span>: <span style="color:#98c379">"admin123"</span>, <span style="color:#98c379">"expected"</span>: <span style="color:#98c379">"登录成功!"</span>},
             {<span style="color:#98c379">"user"</span>: <span style="color:#98c379">""</span>, <span style="color:#98c379">"pwd"</span>: <span style="color:#98c379">"admin123"</span>, <span style="color:#98c379">"expected"</span>: <span style="color:#98c379">"登陆失败,账号或密码错误!"</span>},
             {<span style="color:#98c379">"user"</span>: <span style="color:#98c379">"admin"</span>, <span style="color:#98c379">"pwd"</span>: <span style="color:#98c379">""</span>, <span style="color:#98c379">"expected"</span>: <span style="color:#98c379">"登陆失败,账号或密码错误!"</span>}
             ]


<span style="color:#61aeee">@pytest.mark.parametrize(<span style="color:#3388aa">"test_data"</span>, test_datas, ids=[<span style="color:#3388aa">"输入正确账号、密码,登录成功"</span>,
                                                      <span style="color:#3388aa">"账号为空,密码正确,登录失败"</span>,
                                                      <span style="color:#3388aa">"账号正确,密码为空,登录失败"</span>,
                                                      ])</span>
<span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">test_login</span>(<span style="color:#a6e22e">test_data</span>):</span>
    <span style="color:#b18eb1"><em># 测试用例</em></span>
    res = login(test_data[<span style="color:#98c379">"user"</span>], test_data[<span style="color:#98c379">"pwd"</span>])
    <span style="color:#b18eb1"><em># 断言</em></span>
    <span style="color:#e6c07b">print</span>(<span style="color:#d19a66">111</span>)
    <span style="color:#f92672">assert</span> res[<span style="color:#98c379">"msg"</span>] == test_data[<span style="color:#98c379">"expected"</span>]</span></span>

​ 运行结果:

shell
<span style="background-color:#282c34"><span style="color:#abb2bf">Testing started at 10:34 ...

============================= test session starts =============================
platform win32 -- Python 3.8.1, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- C:\software\python\python.exe
cachedir: .pytest_cache
rootdir: D:\myworkspace\test, inifile: pytest.ini
collecting ... collected 3 items

test.py::test_login[\u8f93\u5165\u6b63\u786e\u8d26\u53f7\u3001\u5bc6\u7801\uff0c\u767b\u5f55\u6210\u529f] PASSED [ 33%]111

test.py::test_login[\u8d26\u53f7\u4e3a\u7a7a\uff0c\u5bc6\u7801\u6b63\u786e\uff0c\u767b\u5f55\u5931\u8d25] PASSED [ 66%]111

test.py::test_login[\u8d26\u53f7\u6b63\u786e\uff0c\u5bc6\u7801\u4e3a\u7a7a\uff0c\u767b\u5f55\u5931\u8d25] PASSED [100%]111


============================== 3 passed in 0.02s ==============================

Process finished with exit code 0
</span></span>

​ 注意: [\u8f93\u5165\u6b63 ...] 这些并不是乱码,是unicode 编码,因为我们输入的是中文,指定一下编码就可以。在项目的根目录的 conftest.py 文件,加以下代码:

python
<span style="background-color:#282c34"><span style="color:#abb2bf"><span style="color:#61aeee"><span style="color:#f92672">def</span> <span style="color:#61aeee">pytest_collection_modifyitems</span>(<span style="color:#a6e22e">items</span>):</span>
    <span style="color:#98c379">"""
    测试用例收集完成时,将收集到的item的name和nodeid的中文显示在控制台上
    :return:
    """</span>
    <span style="color:#f92672">for</span> item <span style="color:#f92672">in</span> items:
        item.name = item.name.encode(<span style="color:#98c379">"utf-8"</span>).decode(<span style="color:#98c379">"unicode_escape"</span>)
        <span style="color:#e6c07b">print</span>(item.nodeid)
        item._nodeid = item.nodeid.encode(<span style="color:#98c379">"utf-8"</span>).decode(<span style="color:#98c379">"unicode_escape"</span>)</span></span>

​ 再运行一遍就可以了。

shell
<span style="background-color:#282c34"><span style="color:#abb2bf">Testing started at 10:38 ...

============================= test session starts =============================
platform win32 -- Python 3.8.1, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- C:\software\python\python.exe
cachedir: .pytest_cache
rootdir: D:\myworkspace\test, inifile: pytest.ini
collecting ... test.py::test_login[\u8f93\u5165\u6b63\u786e\u8d26\u53f7\u3001\u5bc6\u7801\uff0c\u767b\u5f55\u6210\u529f]
test.py::test_login[\u8d26\u53f7\u4e3a\u7a7a\uff0c\u5bc6\u7801\u6b63\u786e\uff0c\u767b\u5f55\u5931\u8d25]
test.py::test_login[\u8d26\u53f7\u6b63\u786e\uff0c\u5bc6\u7801\u4e3a\u7a7a\uff0c\u767b\u5f55\u5931\u8d25]
collected 3 items

test.py::test_login[输入正确账号、密码,登录成功] PASSED                 [ 33%]111

test.py::test_login[账号为空,密码正确,登录失败] PASSED                 [ 66%]111

test.py::test_login[账号正确,密码为空,登录失败] PASSED                 [100%]111


============================== 3 passed in 0.02s ==============================

Process finished with exit code 0</span></span>

最后我邀请你进入我们的【软件测试学习交流群:785128166】, 大家可以一起探讨交流软件测试,共同学习软件测试技术、面试等软件测试方方面面,还会有免费直播课,收获更多测试技巧,我们一起进阶Python自动化测试/测试开发,走向高薪之路

作为一个软件测试的过来人,我想尽自己最大的努力,帮助每一个伙伴都能顺利找到工作。所以我整理了下面这份资源,现在免费分享给大家,有需要的小伙伴可以关注【公众号:程序员二黑】自提!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1420969.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Springboot校验注解

Spring Boot 提供了一组基于 Hibernate Validator 的校验注解&#xff0c;用于验证请求参数、实体对象等数据的合法性。下面是一些常用的 Spring Boot 校验注解及其功能&#xff1a; 导入依赖 <dependency><groupId>org.springframework.boot</groupId><…

正则表达式补充以及sed awk

正则表达式&#xff1a; 下划线算 在单词里面 解释一下过程&#xff1a; 在第二行hello world当中&#xff0c;hello中的h 与后面第一个h相匹配&#xff0c;所以hello中的ello可以和abcde匹配 在world中&#xff0c;w先匹配h匹配不上&#xff0c;则在看0&#xff0c;r&#…

代码随想录算法训练营第二十一天 |530.二叉搜索树的最小绝对差,501.二叉搜索树中的众数,236.二叉树的最近公共祖先(待补充)

530.二叉搜索树的最小绝对差 1、题目链接&#xff1a;力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 2、文章讲解&#xff1a;力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 3、题目&#xff1a; 给你一棵所有节点为非…

Docker基于Dockerfile多级构建LNMP,实现缩小镜像体积

目录 实验准备&#xff1a; 1.创建nginx镜像 2.创建mysql镜像 3.创建php镜像 4.完成对接 创建网络 创建nginx容器 创建mysql容器 创建WordPress库 创建php容器 5.登录验证 6.镜像体积是不是越小越好&#xff1f;为什么要缩减镜像体积&#xff1f; 7.缩小镜像体积的…

防御保护 笔记整理

一、ASPF--- 针对应用层的包过滤 ASPF --- 针对应用层的包过滤 --- 用来抓取多通道协议中协商端口的关键数据包&#xff0c;之后&#xff0c;将端 口算出&#xff0c;将结果记录在sever-map表中&#xff0c;相当于开辟了一条隐形的通道。 FTP --- 文件传输协议 FTP协议是一个典…

数学算法知识编程

&#xff08;1&#xff09;辗转相除法求最大公约数&#xff08;gcd&#xff09; 辗转相除法&#xff0c; 又名欧几里德算法&#xff08;Euclidean algorithm&#xff09;&#xff0c;是求最大公约数的一种方法。它的具体做法是&#xff1a;用较小数除较大数&#xff0c;再用出现…

I.MX6ULL_Linux_驱动篇(53)linux USB驱动

I.MX6ULL USB 接口简介 I.MX6ULL 内部集成了两个独立的 USB 控制器&#xff0c;这两个 USB 控制器都支持 OTG 功能。I.MX6ULL 内部 USB 控制器特性如下&#xff1a; ①、有两个 USB2.0 控制器内核分别为 Core0 和 Core1&#xff0c;这两个 Core 分别连接到 OTG1 和OTG2。 ②、…

基于STM32的CAN通信协议选择与实现

基于STM32的控制器区域网络&#xff08;CAN&#xff09;通信协议是一种常见的实时数据通信方案&#xff0c;适用于需要高速、可靠通信的应用场景&#xff0c;比如汽车网络、工业控制系统等。在这里&#xff0c;我们将详细介绍基于STM32的CAN通信协议的选择与实现。 ✅作者简介&…

使用Win32API实现贪吃蛇小游戏

目录 C语言贪吃蛇项目 基本功能 需要的基础内容 Win32API 介绍 控制台程序部分指令 设置控制台窗口的长宽 设置控制台的名字 控制台在屏幕上的坐标位置结构体COORD 检索指定标准设备的句柄&#xff08;标准输入、标准输出或标准错误&#xff09; 光标信息结构体类型CONSOLE_CUR…

excel给数据库初始化/旧数据处理(自动sql拼装)

思路&#xff1a; 首先导出数据到excel编写单条数据操作的sql利用excel CONCATENATE 函数自动生成&#xff0c;每一行数据的操作sql 小技巧:对于需要套娃的字段值&#xff0c;可以加一个临时列同样使用CONCATENATE函数进行sql拼装 案例&#xff1a; 1.临时列:CONCATENATE(C2, …

HBase(docker版)简单部署和HBase shell操作实践

文章目录 说明HBase部署访问HBase Shell常见命令数据定义语言(DDL) 数据操作语言(DML)通用操作访问HBase WebUI 说明 本文适合HBase初学者快速搭建HBase环境&#xff0c;练习常见shell使用本文参考资料 《大数据技术原理和应用》&#xff08;林子雨 编著 第三版&#xff09;zh…

一文彻底搞懂redis数据结构及应用

文章目录 1. Redis介绍2.五种基本类型2.1 String字符串2.2 List列表2.3 Set集合2.4 Zset有序集合2.5 Hash散列 3. 三种基本类型3.1 Bitmap &#xff08;位存储&#xff09;3.2 HyperLogLogs&#xff08;基数统计&#xff09;3.3 geospatial (地理位置) 4. Stream详解4.1 Stream…

NTRU-Based GSW-Like FHE:Faster Blind Rotation

参考文献&#xff1a; [XZD23] Xiang, B., Zhang, J., Deng, Y., Dai, Y., Feng, D. (2023). Fast Blind Rotation for Bootstrapping FHEs. In: Handschuh, H., Lysyanskaya, A. (eds) Advances in Cryptology – CRYPTO 2023. CRYPTO 2023. Lecture Notes in Computer Scien…

C++_list

目录 一、模拟实现list 1、list的基本结构 2、迭代器封装 2.1 正向迭代器 2.2 反向迭代器 3、指定位置插入 4、指定位置删除 5、结语 前言&#xff1a; list是STL(标准模板库)中的八大容器之一&#xff0c;而STL属于C标准库的一部分&#xff0c;因此在C中可以直接使用…

实现扫码登录

扫码登录是如何实现的&#xff1f; 二维码信息里主要包括唯一的二维码ID,过期的时间&#xff0c;还有扫描状态&#xff1a;未扫描、已扫描、已失效。 扫码登录流程 用户打开网站登录页面的时候&#xff0c;浏览器会向二维码服务器发送一个获取登录二维码的请求。二维码服务器收…

雨云VPS搭建幻兽帕鲁服务器,PalWorld开服联机教程(Windows),0基础保姆级教程

雨云VPS用Windows系统搭建幻兽帕鲁私服&#xff0c;PalWorld开服联机教程&#xff0c;零基础保姆级教程&#xff0c;本教程使用一键脚本来搭建幻兽帕鲁服务端&#xff0c;并讲了如何配置游戏参数&#xff0c;如何更新服务端等。 最近这游戏挺火&#xff0c;很多人想跟朋友联机…

顶象点选验证码

要放假了好颓废。。。。 没啥事儿干&#xff0c;就把之前剩余的顶象点选系列的验证码类型看了下。 之前分享了一篇关于这个顶象的滑块的 DX算法还原_dx算法还原_逆向学习之旅-CSDN博客&#xff0c;感兴趣可以去看看。 咱们以文字点选为例&#xff1a; def get_image_arry(s…

Spring Boot如何统计一个Bean中方法的调用次数

目录 实现思路 前置条件 实现步骤 首先我们先自定义一个注解 接下来定义一个切面 需要统计方法上使用该注解 测试 实现思路 通过AOP即可实现&#xff0c;通过AOP对Bean进行代理&#xff0c;在每次执行方法前或者后进行几次计数统计。这个主要就是考虑好如何避免并发情况…

AI绘画:PhotoMaker Win11本地安装记录!

昨天介绍一个叫PhotoMaker的AI绘画开源项目。挺不错的&#xff01; 通过这个项目可以快速制作特定人脸的AI绘画作品&#xff0c;相比传统的技术效果会好很多&#xff0c;效率也高很多。 今天趁热打铁&#xff0c;本地电脑装装看&#xff0c;并且记录&#xff0c;分享一下&#…

城建档案数字化管理系统

城市建设档案数字化管理系统是指将城市建设相关档案纸质化资料转换为数字化形式&#xff0c;并通过信息技术手段进行存储、检索、管理和利用的系统。该系统旨在解决传统纸质档案管理存在的问题&#xff0c;提高档案管理的效率和准确性。 专久智能城市建设档案数字化管理系统主要…