Compare commits
3 commits
6ab084ff44
...
57180e3596
| Author | SHA1 | Date | |
|---|---|---|---|
|
57180e3596 |
|||
|
8c093733f4 |
|||
|
e739b8f0b8 |
7 changed files with 110 additions and 1 deletions
|
|
@ -81,12 +81,12 @@ cmd_create_init()
|
||||||
echo "import `module_path $f` as $f"
|
echo "import `module_path $f` as $f"
|
||||||
__add_seen $f
|
__add_seen $f
|
||||||
done
|
done
|
||||||
echo
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${#seen[@]} -eq 0 ]; then
|
if [ ${#seen[@]} -eq 0 ]; then
|
||||||
echo "__all__ = []"
|
echo "__all__ = []"
|
||||||
else
|
else
|
||||||
|
echo
|
||||||
echo "__all__ = ["
|
echo "__all__ = ["
|
||||||
for dst_type in ${!seen[@]}; do
|
for dst_type in ${!seen[@]}; do
|
||||||
echo " \"$dst_type\","
|
echo " \"$dst_type\","
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
TOPDIR = ..
|
TOPDIR = ..
|
||||||
|
|
||||||
|
ORDERED_SUBDIRS = unit integration
|
||||||
|
|
||||||
include $(TOPDIR)/make/proj.mk
|
include $(TOPDIR)/make/proj.mk
|
||||||
include $(JWBDIR)/make/dirs.mk
|
include $(JWBDIR)/make/dirs.mk
|
||||||
|
|
|
||||||
4
test/unit/Makefile
Normal file
4
test/unit/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
TOPDIR = ../..
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/dirs.mk
|
||||||
4
test/unit/python/Makefile
Normal file
4
test/unit/python/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
TOPDIR = ../../..
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/dirs.mk
|
||||||
4
test/unit/python/lib/Makefile
Normal file
4
test/unit/python/lib/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
TOPDIR = ../../../..
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/dirs.mk
|
||||||
7
test/unit/python/lib/Uri/Makefile
Normal file
7
test/unit/python/lib/Uri/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
TOPDIR = ../../../../../
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/py-run.mk
|
||||||
|
|
||||||
|
all:
|
||||||
|
test: run
|
||||||
88
test/unit/python/lib/Uri/test.py
Normal file
88
test/unit/python/lib/Uri/test.py
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
import sys, os
|
||||||
|
|
||||||
|
# Mirror the source tree structure so imports resolve correctly
|
||||||
|
src_root = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', 'src', 'python')
|
||||||
|
sys.path.insert(0, src_root)
|
||||||
|
|
||||||
|
from jw.pkg.lib.Uri import Uri
|
||||||
|
|
||||||
|
# Basic URL parsing
|
||||||
|
u = Uri('ssh://john.doe@host:22/path/to/repo')
|
||||||
|
assert u.protocol == 'ssh'
|
||||||
|
assert u.hostname == 'host'
|
||||||
|
assert u.port == 22
|
||||||
|
assert u.path == '/path/to/repo'
|
||||||
|
|
||||||
|
# Username and password
|
||||||
|
u = Uri('https://user:pass@example.com/repo')
|
||||||
|
assert u.username == 'user'
|
||||||
|
assert u.password == 'pass'
|
||||||
|
|
||||||
|
# Credentials in output
|
||||||
|
u = Uri('https://user:secret@example.com/repo')
|
||||||
|
assert 'secret' in u.full # full shows password
|
||||||
|
assert '<hidden>' in u.safe_full_with_username # safe version hides password
|
||||||
|
|
||||||
|
# Scheme defaults to file
|
||||||
|
u = Uri('/local/path')
|
||||||
|
assert u.scheme == 'file://'
|
||||||
|
assert u.protocol == 'file'
|
||||||
|
|
||||||
|
# Pimp returns existing Uri unchanged
|
||||||
|
u1 = Uri('ssh://host/path')
|
||||||
|
u2 = Uri.pimp(u1)
|
||||||
|
assert u2 is u1
|
||||||
|
|
||||||
|
# New with path (add)
|
||||||
|
u = Uri('ssh://host/path')
|
||||||
|
u2 = u.new_add_path('subdir')
|
||||||
|
assert u2.to_string == 'ssh://host/path/subdir'
|
||||||
|
|
||||||
|
# New with path (replace) - to_string is updated
|
||||||
|
u3 = u.new_replace_path('/other')
|
||||||
|
assert u3.to_string == 'ssh://host/other'
|
||||||
|
|
||||||
|
# Authority includes credentials
|
||||||
|
u = Uri('ssh://user:pass@host:22/path')
|
||||||
|
assert u.authority == 'userpass@host:22'
|
||||||
|
|
||||||
|
# Origin excludes credentials
|
||||||
|
assert u.origin == 'host:22'
|
||||||
|
|
||||||
|
# ID and safe version hide password
|
||||||
|
assert u.id == 'ssh://user:<hidden>@host:22'
|
||||||
|
assert '<hidden>' in u.safe_full_with_username
|
||||||
|
|
||||||
|
# Full includes path and credentials
|
||||||
|
assert u.full == 'ssh://userpass@host:22/path'
|
||||||
|
|
||||||
|
# Simple URLs
|
||||||
|
u = Uri('https://example.com/repo.git')
|
||||||
|
assert u.hostname == 'example.com'
|
||||||
|
assert u.path == '/repo.git'
|
||||||
|
assert u.basename == 'repo.git'
|
||||||
|
|
||||||
|
# Username setter
|
||||||
|
u = Uri('ssh://host/path')
|
||||||
|
u.set_username('newuser')
|
||||||
|
assert u.username == 'newuser'
|
||||||
|
|
||||||
|
# Password setter
|
||||||
|
u = Uri('ssh://host/path')
|
||||||
|
u.set_password('newpass')
|
||||||
|
assert u.password == 'newpass'
|
||||||
|
|
||||||
|
# No port
|
||||||
|
u = Uri('ssh://host/path')
|
||||||
|
assert u.port is None
|
||||||
|
assert u.port_str is None
|
||||||
|
|
||||||
|
# to_string returns original
|
||||||
|
u = Uri('ssh://user:pass@host:22/path')
|
||||||
|
assert u.to_string == 'ssh://user:pass@host:22/path'
|
||||||
|
|
||||||
|
# String representation hides credentials
|
||||||
|
u = Uri('https://user:secret@example.com/repo.git')
|
||||||
|
assert '<hidden>' in str(u)
|
||||||
|
|
||||||
|
print('All Uri tests passed')
|
||||||
Loading…
Add table
Add a link
Reference in a new issue