pikapython/examples/os/os_path.py

43 lines
1.3 KiB
Python
Raw Normal View History

2023-03-26 20:43:51 +08:00
import os
p = os.path
assert p.join('dir', 'file.txt') == 'dir/file.txt'
assert p.join('/home/user', 'dir', 'file.txt') == '/home/user/dir/file.txt'
# Test split method
assert p.split('dir/file.txt') == ('dir', 'file.txt')
assert p.split('/home/user/dir/file.txt') == ('/home/user/dir', 'file.txt')
# Test splitext method
assert p.splitext('file.txt') == ('file', '.txt')
assert p.splitext('/home/user/file.tar.gz') == ('/home/user/file.tar', '.gz')
# Test basename method
assert p.basename('dir/file.txt') == 'file.txt'
assert p.basename('/home/user/dir/file.txt') == 'file.txt'
# Test dirname method
assert p.dirname('dir/file.txt') == 'dir'
assert p.dirname('/home/user/dir/file.txt') == '/home/user/dir'
# Test exists method
assert p.exists('config/pika_config_void') == False
assert p.exists('/root/go') == True
# Test isdir method
assert p.isdir('config/pika_config_void.h') == False
assert p.isdir('config') == True
# Test isfile method
assert p.isfile('config') == False
assert p.isfile('config/pika_config_void.h') == True
# Test isabs method
assert p.isabs('dir/file.txt') == False
assert p.isabs('/home/user/file.txt') == True
# Test abspath method
assert p.abspath('config/pika_config_void.h') == "/root/pikascript/port/linux/config/pika_config_void.h"
assert p.abspath('/root/go') == "/root/go"
print("PASS")