Pytest及相关测试工具实战指南

news2026/4/29 7:56:45
一个完整的例子手把手教你从零开始使用PytestPytest-covPylintflake8。例子银行账户系统编写测试 - 检查覆盖率 - 做静态分析 - 代码风格检查第一部分Pytest入门 - 从零到熟练1.1 什么是PytestPytest是Python最流行的测试框架比unittest更简洁强大。安装conda activate mybookwise conda install pytest pytest-cov1.2 创建第一个项目步骤1创建项目文件夹# 创建一个新的学习项目 mkdir learn-testing cd learn-testing # 创建代码文件夹 mkdir bank touch bank/__init__.py touch bank/account.py步骤2编写银行账户类用编辑器打开bank/account.py写入 银行账户模块 class BankAccount: 银行账户类 def __init__(self, account_holder: str, initial_balance: float 0.0): 初始化账户 if initial_balance 0: raise ValueError(初始余额不能为负数) self.account_holder account_holder self._balance initial_balance self.transaction_history [] property def balance(self) - float: 获取余额只读属性 return self._balance def deposit(self, amount: float) - float: 存款 if amount 0: raise ValueError(存款金额必须大于0) self._balance amount self.transaction_history.append(f存款: {amount}) return self._balance def withdraw(self, amount: float) - float: 取款 if amount 0: raise ValueError(取款金额必须大于0) if amount self._balance: raise ValueError(余额不足) self._balance - amount self.transaction_history.append(f取款: -{amount}) return self._balance def transfer(self, target_account: BankAccount, amount: float) - tuple: 转账到另一个账户 if amount 0: raise ValueError(转账金额必须大于0) if amount self._balance: raise ValueError(余额不足无法转账) # 先从当前账户扣款 self.withdraw(amount) # 再存到目标账户 target_account.deposit(amount) self.transaction_history.append(f转账给{target_account.account_holder}: -{amount}) target_account.transaction_history.append(f{self.account_holder}的转账: {amount}) return self._balance, target_account.balance1.3 编写第一个测试步骤1创建测试文件mkdir tests touch tests/__init__.py touch tests/test_account.py步骤2编写基础测试用编辑器打开tests/test_account.py写入 银行账户的单元测试 import pytest from bank.account import BankAccount # 测试类类名要以Test开头 class TestBankAccount: 测试BankAccount类 def test_account_creation(self): 测试账户创建 # 1. 准备数据 account BankAccount(张三, 100.0) # 2. 执行操作 # 这里创建账户就是操作 # 3. 验证结果 assert account.account_holder 张三 assert account.balance 100.0 assert len(account.transaction_history) 0 def test_deposit(self): 测试存款 # 准备 account BankAccount(李四, 50.0) # 执行 new_balance account.deposit(30.0) # 验证 assert new_balance 80.0 assert account.balance 80.0 assert len(account.transaction_history) 1 assert 存款: 30.0 in account.transaction_history[0] def test_withdraw_success(self): 测试成功取款 account BankAccount(王五, 100.0) new_balance account.withdraw(40.0) assert new_balance 60.0 assert 取款: -40.0 in account.transaction_history[0] def test_withdraw_insufficient_balance(self): 测试余额不足取款 account BankAccount(赵六, 50.0) # 验证会抛出异常 with pytest.raises(ValueError, match余额不足): account.withdraw(100.0) def test_withdraw_zero_or_negative(self): 测试取款0或负数 account BankAccount(钱七, 100.0) with pytest.raises(ValueError, match取款金额必须大于0): account.withdraw(0) with pytest.raises(ValueError, match取款金额必须大于0): account.withdraw(-10.0)步骤3运行测试# 进入项目根目录 cd learn-testing # 运行所有测试 pytest # 运行指定测试文件 pytest tests/test_account.py # 运行指定测试类 pytest tests/test_account.py::TestBankAccount # 运行指定测试方法 pytest tests/test_account.py::TestBankAccount::test_deposit # 详细模式 pytest -v # 显示print输出 pytest -s第二部分Pytest高级功能2.1 使用夹具Fixture夹具是Pytest最强大的功能之一用于准备测试数据。修改test_account.py添加夹具# 在import下面添加 import pytest from bank.account import BankAccount # 定义一个夹具 pytest.fixture def empty_account(): 返回一个余额为0的账户 return BankAccount(测试用户, 0.0) pytest.fixture def funded_account(): 返回一个有1000元的账户 return BankAccount(测试用户, 1000.0) # 在测试类中使用夹具 class TestBankAccountWithFixtures: 使用夹具的测试 def test_deposit_with_fixture(self, empty_account): 测试存款使用夹具 new_balance empty_account.deposit(500.0) assert new_balance 500.0 def test_withdraw_with_fixture(self, funded_account): 测试取款使用夹具 new_balance funded_account.withdraw(300.0) assert new_balance 700.02.2 参数化测试一次测试多组数据减少重复代码。# 参数化测试示例 import pytest class TestParameterized: 参数化测试示例 # 测试存款的不同金额 pytest.mark.parametrize(initial, deposit_amount, expected, [ (0, 100, 100), # 从0存100 (50, 30, 80), # 从50存30 (100, 0.01, 100.01), # 存小数 ]) def test_deposit_amounts(self, initial, deposit_amount, expected): 测试不同金额的存款 account BankAccount(测试, initial) new_balance account.deposit(deposit_amount) assert new_balance expected # 测试边界值 pytest.mark.parametrize(withdraw_amount, should_succeed, [ (1, True), # 最小取款1元 (500, True), # 刚好取一半 (999, True), # 取999 (1000, True), # 刚好取完 (1001, False), # 多取1元应该失败 (2000, False), # 多取很多 ]) def test_withdraw_boundaries(self, withdraw_amount, should_succeed): 测试取款的边界值 account BankAccount(测试, 1000.0) if should_succeed: new_balance account.withdraw(withdraw_amount) assert new_balance 1000.0 - withdraw_amount else: with pytest.raises(ValueError, match余额不足): account.withdraw(withdraw_amount)2.3 测试标记Mark用于分类测试可以只运行部分测试。# 标记测试 import pytest class TestWithMarks: 使用标记的测试 pytest.mark.slow def test_slow_operation(self): 标记为慢测试 import time time.sleep(0.5) # 模拟慢操作 assert True pytest.mark.fast def test_fast_operation(self): 标记为快测试 assert True pytest.mark.skip(reason功能还没实现) def test_skip_this(self): 跳过这个测试 assert False pytest.mark.skipif(True, reason条件跳过) def test_skip_if(self): 条件跳过 assert False pytest.mark.xfail def test_expected_to_fail(self): 预期会失败的测试 assert False # 这里预期会失败运行特定标记的测试# 只运行标记为fast的测试 pytest -m fast # 运行标记为slow的测试 pytest -m slow # 运行除slow外的所有测试 pytest -m not slow # 查看所有标记 pytest --markers第三部分测试覆盖率pytest-cov3.1 什么是测试覆盖率覆盖率衡量你的测试覆盖了多少代码包括行覆盖率测试执行了多少行代码分支覆盖率测试覆盖了多少分支if/else函数覆盖率测试覆盖了多少函数3.2 检查覆盖率# 基本覆盖率检查 pytest --covbank # 详细报告显示哪些行没覆盖 pytest --covbank --cov-reportterm-missing # 生成HTML报告 pytest --covbank --cov-reporthtml # 设置最低覆盖率要求 pytest --covbank --cov-fail-under80 # 只计算特定文件 pytest --covbank.account运行后打开htmlcov/index.html可以看到总体覆盖率百分比每个文件的覆盖率点击文件名查看哪些行没被覆盖红色是没覆盖的3.3 提高覆盖率假设我们的覆盖率报告显示account.py的__init__方法中负数检查没被测试# 添加测试来覆盖这个分支 def test_negative_initial_balance(): 测试负数初始余额应该抛异常 with pytest.raises(ValueError, match初始余额不能为负数): BankAccount(测试, -100.0)第四部分静态代码分析pylint4.1 什么是静态代码分析不运行代码只分析代码结构发现潜在问题代码风格问题潜在的bug代码复杂度重复代码4.2 使用pylint# 分析整个bank模块 pylint bank # 只显示错误 pylint -E bank # 生成详细报告 pylint --reportsy bank # 设置分数阈值 pylint --fail-under8.0 bank4.3 修复pylint问题常见问题1缺少文档字符串# 修复前 def some_function(): pass # 修复后 def some_function(): 函数的文档字符串 pass常见问题2变量命名不规范# 修复前 def MyFunction(): # 函数名应该小写 MyVar 1 # 变量名应该小写 # 修复后 def my_function(): my_var 1常见问题3行太长# 修复前 long_line 这是一个非常非常非常非常非常非常非常非常非常非常非常非常长的字符串 # 修复后 long_line ( 这是一个非常非常非常非常非常非常非常 非常非常非常非常非常长的字符串 )常见问题4过于复杂的函数# 修复前 def complex_function(x): if x 0: if x 10: if x % 2 0: return True return False # 修复后 def is_small_positive_even(x): 检查是否是小正偶数 if not (0 x 10): return False return x % 2 0第五部分代码风格检查flake85.1 什么是flake8检查代码是否符合PEP8Python官方代码风格指南。5.2 使用flake8# 检查整个项目 flake8 . # 只检查bank模块 flake8 bank # 显示统计信息 flake8 --statistics bank # 忽略特定错误 flake8 --ignoreE501 bank # 忽略行太长错误5.3 常见flake8错误E501 行太长# 修复前超过79字符 result some_really_long_function_name(with_many_parameters, and_another_one, plus_one_more) # 修复后 result some_really_long_function_name( with_many_parameters, and_another_one, plus_one_more )E302 期望2个空行# 修复前 import os def function1(): pass def function2(): # 这里应该有两个空行 pass # 修复后 import os def function1(): pass def function2(): passW291 尾部空格# 修复前 some_code 1 # 这里有个空格 # 修复后 some_code 1第六部分完整实战项目6.1 扩展银行账户系统让我们扩展bank/account.py添加更多功能# 添加信用账户类 class CreditAccount(BankAccount): 信用账户可以透支 def __init__(self, account_holder: str, credit_limit: float 1000.0): 初始化信用账户 if credit_limit 0: raise ValueError(信用额度不能为负数) super().__init__(account_holder, 0.0) self.credit_limit credit_limit self.used_credit 0.0 property def available_credit(self) - float: 可用信用额度 return self.credit_limit - self.used_credit property def total_available(self) - float: 总额度余额可用信用 return self._balance self.available_credit def withdraw(self, amount: float) - float: 取款可以透支 if amount 0: raise ValueError(取款金额必须大于0) # 如果需要透支 if amount self._balance: credit_needed amount - self._balance if credit_needed self.available_credit: raise ValueError(f额度不足可用额度: {self.total_available}) # 使用信用 self.used_credit credit_needed # 余额设为0 self._balance 0 else: # 不需要透支 self._balance - amount self.transaction_history.append(f取款: -{amount}) return self._balance def repay_credit(self, amount: float) - tuple: 还款 if amount 0: raise ValueError(还款金额必须大于0) if self.used_credit 0: raise ValueError(当前无欠款) # 实际还款金额不能超过欠款 actual_repayment min(amount, self.used_credit) self.used_credit - actual_repayment # 如果有剩余存入余额 remaining amount - actual_repayment if remaining 0: self._balance remaining self.transaction_history.append(f还款: -{actual_repayment}) if remaining 0: self.transaction_history.append(f剩余转存: {remaining}) return self.used_credit, self._balance6.2 编写全面的测试创建tests/test_credit_account.py 信用账户的全面测试 import pytest from bank.account import CreditAccount class TestCreditAccount: 测试信用账户 pytest.fixture def credit_account(self): 返回一个新的信用账户 return CreditAccount(测试用户, credit_limit1000.0) def test_credit_account_creation(self, credit_account): 测试信用账户创建 assert credit_account.account_holder 测试用户 assert credit_account.credit_limit 1000.0 assert credit_account.used_credit 0.0 assert credit_account.available_credit 1000.0 assert credit_account.total_available 1000.0 def test_deposit_to_credit_account(self, credit_account): 测试信用账户存款 # 先存500 credit_account.deposit(500.0) assert credit_account.balance 500.0 assert credit_account.total_available 1500.0 # 500余额 1000信用 def test_withdraw_with_credit(self, credit_account): 测试使用信用取款 # 取1200超过余额使用信用 credit_account.withdraw(1200.0) # 余额为0用了200信用 assert credit_account.balance 0.0 assert credit_account.used_credit 200.0 assert credit_account.available_credit 800.0 def test_withdraw_exceed_limit(self, credit_account): 测试超过总额度取款 with pytest.raises(ValueError, match额度不足): credit_account.withdraw(1500.0) # 超过1000的限额 def test_repay_credit(self, credit_account): 测试还款 # 先取800使用信用 credit_account.withdraw(800.0) assert credit_account.used_credit 800.0 # 还款300 remaining_credit, new_balance credit_account.repay_credit(300.0) assert remaining_credit 500.0 assert new_balance 0.0 def test_repay_more_than_owed(self, credit_account): 测试超额还款 # 先取500 credit_account.withdraw(500.0) # 还700多还200 remaining_credit, new_balance credit_account.repay_credit(700.0) # 欠款为0余额有200 assert remaining_credit 0.0 assert new_balance 200.0 def test_repay_zero(self, credit_account): 测试还款0元 with pytest.raises(ValueError, match还款金额必须大于0): credit_account.repay_credit(0) def test_repay_when_no_debt(self, credit_account): 测试无欠款时还款 with pytest.raises(ValueError, match当前无欠款): credit_account.repay_credit(100.0) # 参数化测试 pytest.mark.parametrize(withdraw_amount, expected_credit_used, should_succeed, [ (500, 500, True), # 用500信用 (1000, 1000, True), # 用1000信用 (1001, 0, False), # 超过限额 (0, 0, False), # 取0元 (-100, 0, False), # 取负数 ]) def test_withdraw_scenarios(self, credit_account, withdraw_amount, expected_credit_used, should_succeed): 测试各种取款场景 if should_succeed: credit_account.withdraw(withdraw_amount) assert credit_account.used_credit expected_credit_used else: with pytest.raises(ValueError): credit_account.withdraw(withdraw_amount)6.3 运行完整测试套件# 1. 运行所有测试 pytest # 2. 检查覆盖率 pytest --covbank --cov-reportterm-missing # 3. 生成HTML覆盖率报告 pytest --covbank --cov-reporthtml # 4. 运行静态分析 pylint bank # 5. 检查代码风格 flake8 bank tests第七部分创建配置文件7.1 创建pytest.ini在项目根目录创建pytest.ini[pytest] testpaths tests python_files test_*.py python_classes Test* python_functions test_* addopts -v --covbank --cov-reportterm-missing --cov-reporthtml --cov-fail-under807.2 创建.pylintrc[MASTER] ignoretests jobs1 [MESSAGES CONTROL] disable C0103, # 允许非snake_case的变量名 R0903, # 允许类有少量公共方法 C0114, # 缺少模块文档字符串 C0115, # 缺少类文档字符串 C0116, # 缺少函数文档字符串 R0913, # 允许函数有多个参数 R0914 # 允许函数有多个局部变量 [FORMAT] max-line-length1207.3 创建.flake8[flake8] max-line-length120 exclude.git,__pycache__,venv ignoreE203,W503第八部分完整工作流程8.1 开发一个功能的完整流程假设我们要添加计算利息功能步骤1编写功能代码# 在account.py中添加 class SavingsAccount(BankAccount): 储蓄账户有利息 def __init__(self, account_holder: str, interest_rate: float 0.03): super().__init__(account_holder, 0.0) self.interest_rate interest_rate def add_interest(self) - float: 计算并添加利息 interest self._balance * self.interest_rate self._balance interest self.transaction_history.append(f利息: {interest:.2f}) return interest步骤2编写测试# 在tests/下创建test_savings_account.py import pytest from bank.account import SavingsAccount def test_savings_account_interest(): 测试利息计算 account SavingsAccount(测试, interest_rate0.1) # 10%利率 account.deposit(1000.0) interest account.add_interest() assert interest 100.0 # 1000 * 10% assert account.balance 1100.0步骤3运行测试pytest tests/test_savings_account.py -v步骤4检查覆盖率pytest --covbank --cov-reportterm-missing步骤5静态分析pylint bank/account.py步骤6代码风格检查flake8 bank/account.py8.2 创建自动化脚本创建run_tests.shLinux/Mac或run_tests.batWindowsrun_tests.batWindowsecho off echo 开始运行完整测试套件... echo. echo 1. 运行单元测试... pytest if %errorlevel% neq 0 ( echo 测试失败 exit /b 1 ) echo. echo 2. 检查覆盖率... pytest --covbank --cov-fail-under85 if %errorlevel% neq 0 ( echo 覆盖率不足85%% exit /b 1 ) echo. echo 3. 静态代码分析... pylint bank --fail-under8.0 if %errorlevel% neq 0 ( echo 代码质量需改进 ) echo. echo 4. 代码风格检查... flake8 bank tests if %errorlevel% neq 0 ( echo 代码风格需改进 ) echo. echo 所有检查完成 pause运行./run_tests.bat第九部分实际应用到你的项目现在你学会了基本知识应用到你的支付信用项目9.1 你的测试结构应该是bookstore/ ├── signals.py # 你的业务代码 └── tests/ ├── __init__.py ├── conftest.py # 共享夹具 ├── unit/ │ ├── __init__.py │ ├── test_signals_core.py # 测试纯函数版本 │ └── test_signals_django.py # 测试Django版本 └── integration/ # 集成测试 └── __init__.py9.2 测试你的支付函数示例# tests/unit/test_signals_core.py import pytest from decimal import Decimal from bookstore.signals import calculate_credit_level_core, process_payment_core def test_credit_level(): 测试信用等级计算 result calculate_credit_level_core(Decimal(1500)) assert result 2 def test_payment(): 测试支付 from bookstore.signals import TestCustomer customer TestCustomer(1, test, Decimal(100), 3, Decimal(0)) success, _, _, updated process_payment_core( customer, Decimal(50), use_creditTrue ) assert success is True9.3 运行测试命令# 在项目根目录运行 pytest bookstore/tests/unit/ -v pytest --covbookstore --cov-reporthtml pylint bookstore flake8 bookstore总结Pytest基础编写和运行测试夹具使用创建可重用的测试数据参数化测试一次测试多组数据测试覆盖率衡量测试完整性静态分析提高代码质量代码风格遵循PEP8规范

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

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

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…