You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

py416

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

py416 - pypi Package Compare versions

Comparing version
0.58
to
0.59
+507
tests/test_files.py
import os
import sys
import time
import pytest
import pytest_check as check
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
import src.py416.files as p4f
import src.py416.variables as p4v
# def test_File(tmp_path):
# os.chdir(str_path := str(tmp_path).replace('\\', '/'))
def test_cd(tmp_path):
str_path = str(tmp_path).replace('\\', '/')
tmp = p4f.cd(f'{str_path}/abc')
check.equal(tmp, os.getcwd().replace('\\', '/'))
@pytest.mark.parametrize('i,o', [
('', ''),
('B', ''),
('C:', 'C:/'),
('D:/', 'D:/'),
('E://', ''),
('f:\\', 'F:/'),
('g;/', ''),
('h/', ''),
('I:/test', ''),
('/J', ''),
])
def test_checkwindrive(i, o):
assert p4f.checkwindrive(i) == o
# def test_checkzip(tmp_path):
# os.chdir(str_path := str(tmp_path).replace('\\', '/'))
def test_copy(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
dname = 'dir'
dname2 = 'dir2'
dpath = f'{str_path}/{dname}'
fname = 'file.txt'
fpath = f'{str_path}/{fname}'
msg = 'message'
msg2 = '\nmore text'
os.makedirs(dpath)
with open(fpath, 'a') as file:
file.write(msg)
p4f.copy(fpath, dpath) # copy file
with open(f'{dpath}/{fname}') as file:
tmp = file.read()
check.equal(tmp, msg)
p4f.copy(dpath, dname2) # copy dir
os.chdir(f'{dname2}/{dname}')
check.equal(os.listdir(), [fname])
os.chdir(str_path)
with open(fpath, 'a') as file:
file.write(msg2)
p4f.copy(fpath, dpath, overwrite=True) # overwrite file
with open(f'{dpath}/{fname}') as file:
tmp = file.read()
check.equal(tmp, f'{msg}{msg2}')
p4f.copy(dpath, dname2, overwrite=True) # overwrite dir
with open(f'{dname2}/{dname}/{fname}') as file:
tmp = file.read()
check.equal(tmp, f'{msg}{msg2}')
def test_delete(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
nums = 1, 2, 3, 4, 5
dirs = [f'{str_path}/dir{a}/subdir{b}' for a in nums for b in nums]
for dir in dirs:
os.makedirs(dir)
if '/dir3/' in dir:
with open(file := f'{dir}/file', 'a') as f:
f.write(f'I am {file}')
[p4f.delete(dir) for dir in os.listdir()]
check.equal(os.listdir(), ['dir3'])
[p4f.delete(dir, force=True) for dir in os.listdir()]
check.equal(os.listdir(), [])
for dir in dirs:
os.makedirs(dir)
if '/dir3/' in dir:
with open(file := f'{dir}/file', 'a') as f:
f.write(f'I am {file}')
with open('file', 'a') as f:
f.write(f'base file')
[p4f.delete(item) for item in os.listdir()]
check.equal(os.listdir(), ['dir3'])
def test_delete_trash(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
nums = 1, 2, 3, 4, 5
dirs = [f'{str_path}/dir{a}/subdir{b}' for a in nums for b in nums]
for dir in dirs:
os.makedirs(dir)
if '/dir3/' in dir:
with open(file := f'{dir}/file', 'a') as f:
f.write(f'I am {file}')
[p4f.delete(dir, trash=True) for dir in os.listdir()]
check.equal(os.listdir(), [])
@pytest.mark.parametrize('i,o', [
('', ''),
('/', '/'),
('\\', '/'),
('D:\\test\\a\\b', 'D:/test/a/b'),
('\\\\bdi\\proj', '//bdi/proj'),
('/Users/Lance', '/Users/Lance'),
])
def test_forslash(i, o):
assert p4f.forslash(i) == o
def test_getcwd():
assert p4f.getcwd() == os.getcwd().replace('\\', '/')
@pytest.mark.parametrize('i,o', [
# Unix
('/', '/'),
('/.', '/'),
('/..', '/'),
('/gfsyt/trw', '/gfsyt/trw'),
('/dir1/dir2/.', '/dir1/dir2'),
('/dir1/dir2/..', '/dir1'),
#Windows
('D:', 'D:/'),
('D:/', 'D:/'),
('D:/test/party/time/baby', 'D:/test/party/time/baby'),
('D:/test/a/.', 'D:/test/a'),
('D:/test/a/..', 'D:/test'),
('//', '//'),
('\\\\bdi-az-data01', '//bdi-az-data01'),
('\\\\bdi-az-data01\\Projects', '//bdi-az-data01/Projects'),
('//bdi-az-data01/Projects/.', '//bdi-az-data01/Projects'),
('//bdi-az-data01/Projects/..', '//bdi-az-data01'),
# None
('', ''),
('folder/..', ''),
])
def test_getpath(i, o):
assert p4f.getpath(i) == o
@pytest.mark.parametrize('i,o', [
# Unix
('/', '/'),
(('/', 'abc', 'def', 'ghi.txt'), '/abc/def/ghi.txt'),
('/Users', '/Users'),
(('/Users/lance', 'docs', 'f1/f2'), '/Users/lance/docs/f1/f2'),
('/mnt/folder/.', '/mnt/folder'),
('/mnt/folder/..', '/mnt'),
(('/mnt', 'folder/.'), '/mnt/folder'),
(('/mnt', 'folder/..'), '/mnt'),
(('/mnt', ''), '/mnt'),
# Windows
('T:', 'T:/'),
('D:/', 'D:/'),
(('G:', 'godaddy'), 'G:/godaddy'),
(((['D:/', 'Windows', 'system32']), ['deleteme']), 'D:/Windows/system32/deleteme'),
('C:/same/.', 'C:/same'),
('C:/up/a/..', 'C:/up'),
(('C:/', 'same/.'), 'C:/same'),
(('C:/', 'up/..'), 'C:/'),
(('C:/', 'up/a/..'), 'C:/up'),
('//', '//'),
('//bdi', '//bdi'),
(('//bdi', 'drive'), '//bdi/drive'),
# None
('', ''),
(('', ''), ''),
('J', 'J'),
(('alpha', 'bet'), 'alpha/bet'),
])
def test_joinpath(i, o):
assert p4f.joinpath(i) == o
def test_listdir(tmp_path):
str_path = str(tmp_path).replace('\\', '/')
d1 = f'{str_path}/testdir'
f1 = f'{str_path}/file.txt'
f2 = f'{d1}/file2.txt'
check.equal(p4f.listdir(str_path), ())
os.makedirs(d1)
check.equal(p4f.listdir(str_path), (d1,))
with open(f1, 'a') as f:
f.write('this is file number 1')
with open(f2, 'a') as f:
f.write('this is file number 2')
check.is_in(d1, p4f.listdir(str_path))
check.is_in(d1, p4f.listdir(str_path, files=False))
check.is_in(f1, p4f.listdir(str_path))
check.is_in(f1, p4f.listdir(str_path, dirs=False))
check.is_in(f2, p4f.listdir(d1))
check.is_in(f2, p4f.listdir(d1, dirs=False))
tmp = p4f.listdir(str_path, recursive=True)
check.is_in(d1, tmp)
check.is_in(f1, tmp)
check.is_in(f2, tmp)
def test_listdir_search(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
dirs = 'a', 'b/1', 'c/1/2', 'd/1/2/3', 'e/1/2/3/a', 'f/1/2/3/b', 'g/1/2/3/c'
files = []
files2 = []
for i, dir in enumerate(dirs):
os.makedirs(dir)
files.append(f'{str_path}/{dir}/file{i}.txt')
files2.append(f'{str_path}/{dir}/letter{i}.txt')
for i, file in enumerate(files):
with open(file, 'a') as f:
f.write(f'msg {i}')
for i, file in enumerate(files2):
with open(file, 'a') as f:
f.write(f'msg {i}')
tree = p4f.listdir(recursive=True, search='*')
for file in files:
check.is_in(file, tree)
for file in files2:
check.is_in(file, tree)
tree = p4f.listdir(recursive=True, search='f*')
for file in files:
check.is_in(file, tree)
for file in files2:
check.is_not_in(file, tree)
tree = p4f.listdir(recursive=True, search='l*')
for file in files:
check.is_not_in(file, tree)
for file in files2:
check.is_in(file, tree)
tree = p4f.listdir(recursive=True, search='*le*')
for file in files:
check.is_in(file, tree)
for file in files2:
check.is_in(file, tree)
def test_listdir_recency(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
files = []
nums = 1, 2, 3, 4, 5
dirs = (f'{str_path}/dir{num}' for num in nums)
now = time.time()
for dir in dirs:
os.makedirs(dir)
files += [f'{dir}/file{num}' for num in nums]
for file in files:
with open(file, 'a') as f:
f.write(f'my name is {file}')
if '/dir1/' in file or '/file1' in file: # 1970
os.utime(file, (1, 1))
if '/dir2/' in file or '/file2' in file: # 40 years ago
os.utime(file, tuple([now - 1_262_304_000] * 2))
if '/file3' in file: # a billion seconds ago
os.utime(file, (now - 1e9, now - 1e9))
if '/dir4/' in file: # an hour ago
os.utime(file, (now - 3600, now - 3600))
tmp = p4f.listdir(dirs=False, recursive=True) # all files
check.equal(len(tmp), 25)
(check.is_in(file, tmp) for file in files)
tmp = p4f.listdir(dirs=False, recursive=True, recency=1e3) # files for which we didn't change the modify date
check.equal(len(tmp), 4)
files_unmodified = [f'{str_path}/dir{a}/file{b}' for a in (3, 5) for b in (4, 5)]
(check.is_in(file, tmp) for file in files_unmodified)
tmp = p4f.listdir(dirs=False, recursive=True, recency=4000) # including an hour
check.equal(len(tmp), 9)
files_hour = files_unmodified + [f'{str_path}/dir4/file{num}' for num in nums]
(check.is_in(file, tmp) for file in files_hour)
tmp = p4f.listdir(dirs=False, recursive=True, recency='11575d') # including a billion seconds
check.equal(len(tmp), 13)
files_2001 = files_hour + [f'{str_path}/dir{num}/file3' for num in (1, 2, 3, 5)]
(check.is_in(file, tmp) for file in files_2001)
tmp = p4f.listdir(dirs=False, recursive=True, recency='15000d17h3m59s') # including 40 years
check.equal(len(tmp), 20)
files_40years = files_2001 + [f'{str_path}/dir2/file{b}' for b in (1, 2, 4, 5)] + [f'{str_path}/dir{a}/file2' for a in (1, 3, 5)]
(check.is_in(file, tmp) for file in files_40years)
tmp = p4f.listdir(dirs=False, recursive=True, recency=2e9) # including 1970 (should now be all)
check.equal(len(tmp), 25)
files_1970 = files_40years + [f'{str_path}/dir1/file{b}' for b in (1, 4, 5)] + [f'{str_path}/dir{a}/file1' for a in (3, 5)]
(check.is_in(file, tmp) for file in files_1970)
def test_listdir_dict(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
files = []
nums = 1, 2, 3, 4, 5
dirs = (f'{str_path}/dir{num}' for num in nums)
now = time.time()
for dir in dirs:
os.makedirs(dir)
files += [f'{dir}/file{num}' for num in nums]
for file in files:
with open(file, 'a') as f:
f.write(f'my name is {file}')
if '/dir1/' in file or '/file1' in file: # 1970
os.utime(file, (1, 1))
if '/dir2/' in file or '/file2' in file: # 40 years ago
os.utime(file, tuple([now - 1_262_304_000] * 2))
if '/file3' in file: # a billion seconds ago
os.utime(file, (now - 1e9, now - 1e9))
if '/dir4/' in file: # an hour ago
os.utime(file, (now - 3600, now - 3600))
tmp = p4f.listdir(recursive=True, return_dict=True)
check.is_(type(tmp), dict)
check.equal(len(tmp), 30)
(check.is_in(file, tmp) for file in files)
# def test_log(tmp_path):
# os.chdir(str_path := str(tmp_path).replace('\\', '/'))
def test_makedirs(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
dirs = ['abc', 'def', ('ghi', ['jkl'])], ('mno', ('pqr')), [[['stu/sub'], ['vwx/sub/sub']], ('yz/a/b/c/d/e/f/g',)]
bad = p4f.makedirs(dirs)
check.equal(bad, ())
tmp = os.listdir()
tmp.sort()
check.equal(tmp, ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'])
os.chdir('stu/sub')
os.chdir('../..')
os.chdir('vwx/sub/sub')
os.chdir('../../..')
os.chdir('yz/a/b/c/d/e/f/g')
def test_makefile(tmp_path):
str_path = str(tmp_path).replace('\\', '/')
fname = 'test.txt'
fpath = f'{str_path}/{fname}'
p4f.makefile(fpath, 'message')
check.equal(os.listdir(str_path), [fname])
with open(fpath, 'r', encoding='utf-8') as file:
tmp = file.read()
check.equal(tmp, 'message')
try:
p4f.makefile(fpath, 'message2')
raise Exception('that should\'ve failed')
except FileExistsError:
pass
p4f.makefile(fpath, 'message3', overwrite=True)
with open(fpath, 'r', encoding='utf-8') as file:
tmp3 = file.read()
check.equal(tmp3, 'message3')
p4f.makefile(fpath, overwrite=True)
with open(fpath, 'r', encoding='utf-8') as file:
tmp3 = file.read()
check.equal(tmp3, '')
def test_move(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
dname = 'dir'
dname2 = 'dir2'
fname = 'file.txt'
msg = 'message'
msg2 = '\nmore text'
with open(fname, 'a') as file:
file.write(msg)
tmp = os.listdir()
check.is_not_in(dname, tmp)
check.is_in(fname, tmp)
p4f.move(fname, dname) # move file
tmp = os.listdir()
check.is_not_in(fname, tmp)
tmp = os.listdir(dname)
check.is_in(fname, tmp)
with open(fname, 'a') as file:
file.write(msg2)
p4f.move(fname, dname, overwrite=True) # overwrite file
tmp = os.listdir()
check.is_not_in(fname, tmp)
with open(f'{dname}/{fname}', 'r') as file:
tmp = file.read()
check.equal(tmp, msg2)
p4f.move(dname, dname2) # move dir
tmp = os.listdir()
check.is_in(dname2, tmp)
check.is_not_in(dname, tmp)
check.is_in(dname, os.listdir(dname2))
os.makedirs(dname)
with open(f'{dname}/{fname}', 'a') as file:
file.write(msg)
p4f.move(dname, dname2, overwrite=True) # overwrite dir
tmp = os.listdir()
check.is_not_in(dname, tmp)
with open(f'{dname2}/{dname}/{fname}', 'r') as file:
tmp = file.read()
check.equal(tmp, msg)
@pytest.mark.parametrize('i,o', [
# Unix
('/', '/'),
('/.', '/'),
('/..', '/'),
('/gfsyt/trw', '/gfsyt'),
('/dir1/dir2/.', '/dir1'),
('/dir1/dir2/..', '/'),
# Windows
('D:', 'D:/'),
('D:/', 'D:/'),
('D:/test/party/time/baby', 'D:/test/party/time'),
('D:/test/a/.', 'D:/test'),
('D:/test/a/..', 'D:/'),
('//', '//'),
('\\\\bdi-az-data01', '//bdi-az-data01'),
('\\\\bdi-az-data01\\Projects', '//bdi-az-data01'),
('//bdi-az-data01/Projects/.', '//bdi-az-data01'),
('//bdi-az-data01/Projects/..', '//bdi-az-data01'),
# None
('', ''),
('folder/..', ''),
])
def test_parent(i, o):
assert p4f.parent(i) == o
def test_parent_default(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
assert p4f.parent() == os.path.dirname(os.getcwd()).replace('\\', '/')
def test_readfile(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
file = 'file.txt'
msg = 'some text\nin here'
with open(file, 'a') as f:
f.write(msg)
read = p4f.readfile(file)
check.equal(read, msg)
def test_rename(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
dname = 'dir'
dname2 = 'anotherdir'
fname = 'file.txt'
fname2 = 'somefile.csv'
msg = 'message'
os.makedirs(dname)
with open(fname, 'a') as file:
file.write(msg)
tmp = os.listdir()
check.is_in(dname, tmp)
check.is_not_in(dname2, tmp)
check.is_in(fname, tmp)
check.is_not_in(fname2, tmp)
p4f.rename(dname, dname2)
p4f.rename(fname, fname2)
tmp = os.listdir()
check.is_in(dname2, tmp)
check.is_not_in(dname, tmp)
check.is_in(fname2, tmp)
check.is_not_in(fname, tmp)
def test_rmdir(tmp_path):
os.chdir(str_path := str(tmp_path).replace('\\', '/'))
nums = 1, 2, 3, 4, 5
[os.makedirs(f'dir{a}/subdir{b}') for a in nums for b in nums]
for file in (f'dir{a}/file{b}' for a in (1, 3) for b in (1, 2, 3)):
with open(file, 'a') as f:
f.write(f'i am {file}')
for file in (f'dir{a}/subdir{b}/subfile{c}' for a in (2, 4) for b in (1, 4, 5) for c in (1, 2, 3, 4, 5)):
with open(file, 'a') as f:
f.write(f'i am {file}')
check.equal(p4f.rmdir('dir1'), 5)
check.equal(p4f.rmdir('dir2'), 2)
check.equal(p4f.rmdir('dir3'), 5)
check.equal(p4f.rmdir('dir4'), 2)
check.equal(p4f.rmdir('dir5', delroot=True), 6)
[os.makedirs(dir) for a in nums for b in nums if not os.path.exists(dir := f'dir{a}/subdir{b}')]
check.equal(p4f.rmdir('.', delroot=True), 20)
@pytest.mark.parametrize('i,o', [
# Unix
('/', ('/',)),
('/.', ('/',)),
('/..', ('/',)),
('/gfsyt/trw', ('/', 'gfsyt', 'trw')),
('/dir1/dir2/.', ('/', 'dir1', 'dir2')),
('/dir1/dir2/..', ('/', 'dir1')),
# Windows
('D:', ('D:/',)),
('D:/', ('D:/',)),
('D:/test/party/time/baby', ('D:/', 'test', 'party', 'time', 'baby')),
('D:/test/a/.', ('D:/', 'test', 'a')),
('D:/test/a/..', ('D:/', 'test')),
('//', ('//',)),
('\\\\bdi-az-data01', ('//bdi-az-data01',)),
('\\\\bdi-az-data01\\Projects', ('//bdi-az-data01', 'Projects')),
('//bdi-az-data01/Projects/.', ('//bdi-az-data01', 'Projects')),
('//bdi-az-data01/Projects/..', ('//bdi-az-data01',)),
# None
('', ('',)),
('folder/..', ('',))
])
def test_splitpath(i, o):
assert p4f.splitpath(i) == o
# def test_unzip(tmp_path):
# os.chdir(str_path := str(tmp_path).replace('\\', '/'))
# def test_unzipdir(tmp_path):
# os.chdir(str_path := str(tmp_path).replace('\\', '/'))
# from datetime import datetime as dt
# now = str(dt.now()).split('.')[0].replace(' ', '__').replace(':', '-')
# p4f.makedirs(dir := f'D:/pytest-temp/{now}')
# test_delete_trash(dir)
import os
from pathlib import Path
import sys
import pytest
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
import src.py416.general as g
from src.py416.files import File
@pytest.mark.parametrize('i,o', [
(0, '0B'),
(1500, '1.46KiB'),
(123_456_789, '117.74MiB'),
(65_487_894_231, '60.99GiB'),
(875_467_423_467_423, '796.23TiB'),
(98_700_798_765_465_465, '87.66PiB'),
(4_317_897_564_234_897_842, '3.75EiB'),
(12_345_678_901_234_567_890_123, '10.46ZiB'),
(987_654_321_987_654_321_987_654_321, '816.97YiB'),
(10**28, '8271.81YiB'),
])
def test_bytesize(i, o):
assert g.bytesize(i) == o
@pytest.mark.parametrize('i,o', [
(0, '0B'),
(1500, '1.50KB'),
(123_456_789, '123.46MB'),
(65_487_894_231, '65.49GB'),
(875_467_423_467_423, '875.47TB'),
(98_700_798_765_465_465, '98.70PB'),
(4_317_897_564_234_897_842, '4.32EB'),
(12_345_678_901_234_567_890_123, '12.35ZB'),
(987_654_321_987_654_321_987_654_321, '987.65YB'),
(10**28, '10000.00YB'),
])
def test_bytesize_si(i, o):
assert g.bytesize(i, si=True) == o
def test_emailsmtp():
pass
@pytest.mark.parametrize('i,o', [
(bool(), 'bool'),
(True, 'bool'),
(False, 'bool'),
(bytes(), 'bytes'),
(b'', 'bytes'),
(b'hello', 'bytes'),
(b'\xE2\x82\xAC', 'bytes'),
(bytearray(), 'bytearray'),
(complex(), 'complex'),
(dict(), 'dict'),
({}, 'dict'),
({1: 2}, 'dict'),
({'a': 416, True: False}, 'dict'),
(float(), 'float'),
(0.0, 'float'),
(-0.0, 'float'),
(12.3456789, 'float'),
(-9001.001, 'float'),
(12., 'float'),
(-9001., 'float'),
(1000 / 11, 'float'),
(1000 / 10, 'float'),
(frozenset(), 'frozenset'),
(int(), 'int'),
(0, 'int'),
(-0, 'int'),
(123, 'int'),
(-123456, 'int'),
(list(), 'list'),
([], 'list'),
(['j', 26, {}], 'list'),
(memoryview(b''), 'memoryview'),
(None, 'NoneType'),
(range(1), 'range'),
(set(), 'set'),
({1, 2, 'horse'}, 'set'),
(str(), 'str'),
('', 'str'),
('mystring', 'str'),
(f'{69420}blaze', 'str'),
(r'\example\n', 'str'),
(tuple(), 'tuple'),
((), 'tuple'),
((45,), 'tuple'),
((1, 2, 'yeah'), 'tuple'),
((3, f'g', {6, 7}), 'tuple'),
((True, 98), 'tuple'),
(File(''), 'src.py416.files.File'),
])
def test_gettype(i, o):
assert g.gettype(i) == o
def test_gettype_Path():
p = Path()
if os.name == 'nt':
assert g.gettype(p) == 'pathlib.WindowsPath'
elif os.name == 'posix':
assert g.gettype(p) == 'pathlib.PosixPath'
def test_lineno():
assert g.lineno() == 127
@pytest.mark.parametrize('i,o', [
('january', '01'),
('February', '02'),
('mArCh', '03'),
('APRIL', '04'),
('may', '05'),
('junE', '06'),
('july', '07'),
('august', '08'),
('SEPtember', '09'),
('ocTOber', '10'),
('november', '11'),
('December', '12'),
('', ''),
('jan', ''),
('greq', ''),
('March_2022', ''),
('AprilApril', ''),
('maytheforce', ''),
('timeInJune', ''),
('where july', ''),
])
def test_month2num(i, o):
assert g.month2num(i) == o
def test_pprint():
mydict = {
'a': 1,
'b': 2_000_000_000,
'c': 'a happy cat',
# 'deez nuts': 3.14159_26535_89793_23846_26433,
34: {1: 'ayy', 2: 'bee'},
# 'list': [1, 2, 3],
}
mylist = [
'alpha',
'bravo charlie',
1234567890,
2.7,
[1, 2],
[4, 5, [6, 7, [8, 9, 10]]],
]
myset = {
'alpha',
'bravo charlie',
1234567890,
2.7,
frozenset({1, 2}),
}
mytuple = (
'alpha',
'bravo charlie',
1234567890,
2.7,
(1, 2),
(4, 5, (6, 7, (8, 9, 10))),
)
mylisttuple = [
'a',
('b',),
['c', 'd'],
([([('eeeee',)],)],),
]
@pytest.mark.parametrize('i,a,o', [
(3, '', ('03s', 3, 0, 0, 0)),
(505, ' ', ('08m 25s', 25, 8, 0, 0)),
(12345, '', ('03h25m45s', 45, 25, 3, 0)),
(12345678, '--', ('142d--21h--21m--18s', 18, 21, 21, 142)),
(-46834, ',', ('13h,34s', 34, 0, 13, 0)),
])
def test_secmod(i, a, o):
assert g.secmod(i, sep=a) == o
@pytest.mark.parametrize('i,o', [
('3d16h42m7s', 319327),
('1d', 86400),
('04h16m02s', 15362),
('1s', 1),
('2m', 120),
('3m4s', 184),
('5h', 18_000),
('6h7m', 22_020),
('8h9s', 28_809),
('10h11m12s', 36_672),
('13d', 1_123_200),
('14d15h', 1_263_600),
('16d17m', 1_383_420),
('18d19s', 1_555_219),
('20d21h22m', 1_804_920),
('23d24h25s', 2_073_625),
('26d27m28s', 2_248_048),
('29d30h31m32s', 2_615_492),
])
def test_secmod_inverse(i, o):
assert g.secmod_inverse(i) == o
def test_timestamp():
pass
@pytest.mark.parametrize('i,o', [
('', ('',)),
([], ()),
([1], (1,)),
([1, [2]], (1, 2)),
([1, (2, [3])], (1, 2, 3)),
((), ()),
((1,), (1,)),
((1, (2,)), (1, 2)),
((1, [2, (3,)]), (1, 2, 3)),
(((((([[[['arf', (65432, 'woof')]], 65]])), 6))), ('arf', 65432, 'woof', 65, 6)),
])
def test_unpack(i, o):
assert g.unpack(i) == o
import os
from pprint import pprint
import sys
import time
import pytest
import pytest_check as check
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
import src.py416.sysinfo as p4s
# pprint(p4s.cpu())
# pprint(p4s.disks(), width=1)
# pprint(p4s.ram(), width=1)
# pprint(p4s.system(), width=100)
# pprint(p4s.users(), width=100)
# pprint(p4s.full(), width=1)
# print(p4s.cpu(json=True))
# print(p4s.disks(json=True))
# print(p4s.ram(json=True))
# print(p4s.system(json=True))
# print(p4s.users(json=True))
# print(p4s.full(json=True))
+0
-0

@@ -0,0 +0,0 @@ GNU LESSER GENERAL PUBLIC LICENSE

+1
-1
Metadata-Version: 2.1
Name: py416
Version: 0.58
Version: 0.59
Summary: don't question my methods

@@ -5,0 +5,0 @@ Author-email: Ezio416 <ezezio416@gmail.com>

@@ -7,3 +7,3 @@ [build-system]

name = "py416"
version = "0.58"
version = "0.59"
authors = [

@@ -10,0 +10,0 @@ { name="Ezio416", email="ezezio416@gmail.com" },

Metadata-Version: 2.1
Name: py416
Version: 0.58
Version: 0.59
Summary: don't question my methods

@@ -5,0 +5,0 @@ Author-email: Ezio416 <ezezio416@gmail.com>

@@ -13,2 +13,5 @@ LICENSE

src/py416.egg-info/requires.txt
src/py416.egg-info/top_level.txt
src/py416.egg-info/top_level.txt
tests/test_files.py
tests/test_general.py
tests/test_sysinfo.py

@@ -5,4 +5,4 @@ '''

Created: 2022-08-15
Updated: 2022-12-17
Version: 0.58
Updated: 2023-02-22
Version: 0.59

@@ -12,3 +12,3 @@ A collection of various functions

from .general import *
__version__ = 0, 58
__version__ = 0, 59
v = __version__
'''
| Author: Ezio416
| Created: 2022-08-16
| Updated: 2022-11-10
| Updated: 2023-02-22

@@ -829,3 +829,3 @@ - Functions for filesystem and path string manipulation

def parent(path: str) -> str:
def parent(path: str = '.') -> str:
'''

@@ -838,2 +838,3 @@ - gets the folder containing something

- path to find the parent of
- default: current working directory

@@ -1019,3 +1020,3 @@ Returns

def unzipdir(path: str, ignore_errors: bool = True) -> int:
def unzipdir(path: str = '.', ignore_errors: bool = True) -> int:
'''

@@ -1030,2 +1031,3 @@ - unzips all archives in a folder (only 1st level) until it is unable to continue

- folder containing archive files
- default: current working directory

@@ -1032,0 +1034,0 @@ ignore_errors: bool