python unittest源码解析三----loader.py之_get_name_from_path(self, path)
来源:互联网 发布:耳机声音放大器软件 编辑:程序博客网 时间:2024/06/01 08:55
def _get_name_from_path(self, path): path = os.path.splitext(os.path.normpath(path))[0] _relpath = os.path.relpath(path, self._top_level_dir) assert not os.path.isabs(_relpath), "Path must be within the project" assert not _relpath.startswith('..'), "Path must be within the project" name = _relpath.replace(os.path.sep, '.') return name
这个方法一开始先对传入的路径进行正常的格式化,使用os.path.normpath,官方注释:
- os.path.normpath(path)
Normalize a pathname by collapsing redundant separators and up-levelreferences so thatA//B,A/B/, A/./B andA/foo/../B allbecomeA/B. This string manipulation may change the meaning of a paththat contains symbolic links. On Windows, it converts forward slashes tobackward slashes. To normalize case, usenormcase().
- os.path.splitext(path)
Split the pathname path into a pair (root,ext) such thatroot+ext ==path, andext is empty or begins with a period and contains at most oneperiod. Leading periods on the basename are ignored;splitext('.cshrc')returns('.cshrc','').
- os.path.relpath(path[,start])
Return a relative filepath to path either from the current directory orfrom an optionalstart directory. This is a path computation: thefilesystem is not accessed to confirm the existence or nature ofpath orstart.
- str.replace(old,new[,count])
Return a copy of the string with all occurrences of substring old replaced bynew. If the optional argument count is given, only the firstcountoccurrences are replaced.
- python unittest源码解析三----loader.py之_get_name_from_path(self, path)
- python unittest源码解析二----Test Discovery
- selenium-Python之unittest(三)
- Python Unittest源码分析
- faster rcnn 源码解析之anchor_target_layer.py
- python测试之unittest
- python测试之unittest
- Python 之unittest框架
- Python之unittest
- python笔记之unittest
- python单元测试之unittest
- python unittest源码解析四----关于源码中的__unittest的用处
- Python之使用unittest框架和HTMLTestRunner.py文件实现多个测试用例执行与测试报告生成
- python unittest源码解析一----测试用例是如何被执行的
- python unittest框架的使用&解析
- Django源码解析:setting.py
- 源码解析 Universal Image Loader
- Universal-Image-Loader源码解析
- Ubuntu12.04 cmake 安装
- [Centos]编译安装apache 2.4
- Android初学习 - Fragment解析03
- 酒与污水定律
- 网络负载问题
- python unittest源码解析三----loader.py之_get_name_from_path(self, path)
- Actionbar 切换布局
- 在数组中,插入一个数,并输出。
- 求一个字符串中连续出现次数最多的子串
- Android layout布局属性、标签属性
- 个性化WinPE封装方法----制作过程需要了解的“命令”
- UITabBarController 【标签控制器】自己的见解
- 测试能否对标准输入设置偏移量
- 开通CSDN学院视频课程——小飞鱼通达OA工作流设计制作视频课程