mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 15:08:39 +00:00
linting
This commit is contained in:
15
check-syntax.sh
vendored
15
check-syntax.sh
vendored
@@ -36,14 +36,14 @@ fi
|
|||||||
echo "=> pyflakes version:"
|
echo "=> pyflakes version:"
|
||||||
pyflakes --version
|
pyflakes --version
|
||||||
|
|
||||||
echo "---------------------"
|
|
||||||
|
|
||||||
# check shell scripts
|
# check shell scripts
|
||||||
# SC2002: Useless cat
|
# SC2002: Useless cat
|
||||||
# SC2126: Consider using grep -c instead of grep|wc -l
|
# SC2126: Consider using grep -c instead of grep|wc -l
|
||||||
# SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects
|
# SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects
|
||||||
# SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?
|
# SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?
|
||||||
|
echo "--------------------------------------"
|
||||||
echo "checking shell scripts with shellcheck"
|
echo "checking shell scripts with shellcheck"
|
||||||
|
echo "--------------------------------------"
|
||||||
find . -iname '*.sh' | while read -r script; do
|
find . -iname '*.sh' | while read -r script; do
|
||||||
echo "checking ${script}"
|
echo "checking ${script}"
|
||||||
shellcheck -x \
|
shellcheck -x \
|
||||||
@@ -55,7 +55,9 @@ find . -iname '*.sh' | while read -r script; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# check other python scripts
|
# check other python scripts
|
||||||
|
echo "-----------------------------------------"
|
||||||
echo "checking other python scripts with pylint"
|
echo "checking other python scripts with pylint"
|
||||||
|
echo "-----------------------------------------"
|
||||||
find . -name "*.py" -not -path "./dotdrop/*" | while read -r script; do
|
find . -name "*.py" -not -path "./dotdrop/*" | while read -r script; do
|
||||||
echo "checking ${script}"
|
echo "checking ${script}"
|
||||||
pylint -sn \
|
pylint -sn \
|
||||||
@@ -68,16 +70,22 @@ done
|
|||||||
# PEP8 tests
|
# PEP8 tests
|
||||||
# W503: Line break occurred before a binary operator
|
# W503: Line break occurred before a binary operator
|
||||||
# W504: Line break occurred after a binary operator
|
# W504: Line break occurred after a binary operator
|
||||||
|
echo "---------------------------------"
|
||||||
echo "checking dotdrop with pycodestyle"
|
echo "checking dotdrop with pycodestyle"
|
||||||
|
echo "---------------------------------"
|
||||||
pycodestyle --ignore=W503,W504 dotdrop/
|
pycodestyle --ignore=W503,W504 dotdrop/
|
||||||
pycodestyle scripts/
|
pycodestyle scripts/
|
||||||
|
|
||||||
# pyflakes tests
|
# pyflakes tests
|
||||||
|
echo "------------------------------"
|
||||||
echo "checking dotdrop with pyflakes"
|
echo "checking dotdrop with pyflakes"
|
||||||
|
echo "------------------------------"
|
||||||
pyflakes dotdrop/
|
pyflakes dotdrop/
|
||||||
|
|
||||||
# pylint
|
# pylint
|
||||||
|
echo "----------------------------"
|
||||||
echo "checking dotdrop with pylint"
|
echo "checking dotdrop with pylint"
|
||||||
|
echo "----------------------------"
|
||||||
# https://pylint.pycqa.org/en/latest/user_guide/checkers/features.html
|
# https://pylint.pycqa.org/en/latest/user_guide/checkers/features.html
|
||||||
# R0902: too-many-instance-attributes
|
# R0902: too-many-instance-attributes
|
||||||
# R0913: too-many-arguments
|
# R0913: too-many-arguments
|
||||||
@@ -98,6 +106,9 @@ pylint \
|
|||||||
--disable=R0904 \
|
--disable=R0904 \
|
||||||
dotdrop/
|
dotdrop/
|
||||||
|
|
||||||
|
echo "------------------------"
|
||||||
|
echo "checking for more issues"
|
||||||
|
echo "------------------------"
|
||||||
set +e
|
set +e
|
||||||
exceptions="save_uservariables_name\|@@\|diff_cmd\|original,\|modified,"
|
exceptions="save_uservariables_name\|@@\|diff_cmd\|original,\|modified,"
|
||||||
# f-string errors and missing f literal
|
# f-string errors and missing f literal
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ def check_links(urls):
|
|||||||
allow_redirects=True,
|
allow_redirects=True,
|
||||||
headers=HEADERS).status_code
|
headers=HEADERS).status_code
|
||||||
if ret not in VALID_RET:
|
if ret not in VALID_RET:
|
||||||
|
msg = (
|
||||||
|
f' [WARN] HEAD {url} returned {ret}'
|
||||||
|
f' ... checking with GET'
|
||||||
|
)
|
||||||
|
print(msg)
|
||||||
verb = 'get'
|
verb = 'get'
|
||||||
ret = requests.get(url,
|
ret = requests.get(url,
|
||||||
timeout=TIMEOUT,
|
timeout=TIMEOUT,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from tests.helpers import create_dir, get_string, get_tempdir, clean, \
|
|||||||
|
|
||||||
|
|
||||||
class TestUpdate(unittest.TestCase):
|
class TestUpdate(unittest.TestCase):
|
||||||
|
"""unit test"""
|
||||||
|
|
||||||
CONFIG_BACKUP = False
|
CONFIG_BACKUP = False
|
||||||
CONFIG_CREATE = True
|
CONFIG_CREATE = True
|
||||||
@@ -46,16 +47,16 @@ class TestUpdate(unittest.TestCase):
|
|||||||
self.addCleanup(clean, dotfilespath)
|
self.addCleanup(clean, dotfilespath)
|
||||||
|
|
||||||
# create the dotfiles to test
|
# create the dotfiles to test
|
||||||
d1, c1 = create_random_file(fold_config)
|
d1, _ = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d1))
|
self.assertTrue(os.path.exists(d1))
|
||||||
self.addCleanup(clean, d1)
|
self.addCleanup(clean, d1)
|
||||||
|
|
||||||
d2, c2 = create_random_file(fold_config)
|
d2, _ = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d2))
|
self.assertTrue(os.path.exists(d2))
|
||||||
self.addCleanup(clean, d2)
|
self.addCleanup(clean, d2)
|
||||||
|
|
||||||
# template
|
# template
|
||||||
d3t, c3t = create_random_file(fold_config)
|
d3t, _ = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d3t))
|
self.assertTrue(os.path.exists(d3t))
|
||||||
self.addCleanup(clean, d3t)
|
self.addCleanup(clean, d3t)
|
||||||
|
|
||||||
@@ -74,9 +75,9 @@ class TestUpdate(unittest.TestCase):
|
|||||||
dir1sub2str = 'sub2'
|
dir1sub2str = 'sub2'
|
||||||
sub2 = os.path.join(dir1, dir1sub2str)
|
sub2 = os.path.join(dir1, dir1sub2str)
|
||||||
create_dir(sub2)
|
create_dir(sub2)
|
||||||
f1s1, f1s1c1 = create_random_file(sub1)
|
f1s1, _ = create_random_file(sub1)
|
||||||
self.assertTrue(os.path.exists(f1s1))
|
self.assertTrue(os.path.exists(f1s1))
|
||||||
f1s2, f1s2c1 = create_random_file(sub2)
|
f1s2, _ = create_random_file(sub2)
|
||||||
self.assertTrue(os.path.exists(f1s2))
|
self.assertTrue(os.path.exists(f1s2))
|
||||||
|
|
||||||
# create the directory to test
|
# create the directory to test
|
||||||
@@ -93,38 +94,38 @@ class TestUpdate(unittest.TestCase):
|
|||||||
backup=self.CONFIG_BACKUP,
|
backup=self.CONFIG_BACKUP,
|
||||||
create=self.CONFIG_CREATE)
|
create=self.CONFIG_CREATE)
|
||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
o.update_showpatch = True
|
opt.update_showpatch = True
|
||||||
dfiles = [d1, dir1, d2, d3t, dsubstmp]
|
dfiles = [d1, dir1, d2, d3t, dsubstmp]
|
||||||
|
|
||||||
# import the files
|
# import the files
|
||||||
o.import_path = dfiles
|
opt.import_path = dfiles
|
||||||
cmd_importer(o)
|
cmd_importer(opt)
|
||||||
|
|
||||||
# get new config
|
# get new config
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
o.update_showpatch = True
|
opt.update_showpatch = True
|
||||||
o.debug = True
|
opt.debug = True
|
||||||
trans = Transform('trans', 'cp -r {0} {1}')
|
trans = Transform('trans', 'cp -r {0} {1}')
|
||||||
d3tb = os.path.basename(d3t)
|
d3tb = os.path.basename(d3t)
|
||||||
for dotfile in o.dotfiles:
|
for dotfile in opt.dotfiles:
|
||||||
if os.path.basename(dotfile.dst) == d3tb:
|
if os.path.basename(dotfile.dst) == d3tb:
|
||||||
# patch the template
|
# patch the template
|
||||||
src = os.path.join(o.dotpath, dotfile.src)
|
src = os.path.join(opt.dotpath, dotfile.src)
|
||||||
src = os.path.expanduser(src)
|
src = os.path.expanduser(src)
|
||||||
edit_content(src, '{{@@ profile @@}}')
|
edit_content(src, '{{@@ profile @@}}')
|
||||||
left = os.path.realpath(os.path.basename(dotfile.dst))
|
left = os.path.realpath(os.path.basename(dotfile.dst))
|
||||||
right = os.path.realpath(dirsubs)
|
right = os.path.realpath(dirsubs)
|
||||||
if left == right:
|
if left == right:
|
||||||
# retrieve the path of the sub in the dotpath
|
# retrieve the path of the sub in the dotpath
|
||||||
d1indotpath = os.path.join(o.dotpath, dotfile.src)
|
d1indotpath = os.path.join(opt.dotpath, dotfile.src)
|
||||||
d1indotpath = os.path.expanduser(d1indotpath)
|
d1indotpath = os.path.expanduser(d1indotpath)
|
||||||
dotfile.trans_w = trans
|
dotfile.trans_w = trans
|
||||||
|
|
||||||
# update template
|
# update template
|
||||||
o.update_path = [d3t]
|
opt.update_path = [d3t]
|
||||||
self.assertFalse(cmd_update(o))
|
self.assertFalse(cmd_update(opt))
|
||||||
|
|
||||||
# update sub dirs
|
# update sub dirs
|
||||||
gone = os.path.join(d1indotpath, dir1string)
|
gone = os.path.join(d1indotpath, dir1string)
|
||||||
@@ -132,8 +133,8 @@ class TestUpdate(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(gone))
|
self.assertTrue(os.path.exists(gone))
|
||||||
clean(sub1) # dir1sub1str
|
clean(sub1) # dir1sub1str
|
||||||
self.assertTrue(os.path.exists(gone))
|
self.assertTrue(os.path.exists(gone))
|
||||||
o.update_path = [dsubstmp]
|
opt.update_path = [dsubstmp]
|
||||||
cmd_update(o)
|
cmd_update(opt)
|
||||||
self.assertFalse(os.path.exists(gone))
|
self.assertFalse(os.path.exists(gone))
|
||||||
|
|
||||||
# edit the files
|
# edit the files
|
||||||
@@ -141,7 +142,7 @@ class TestUpdate(unittest.TestCase):
|
|||||||
edit_content(dirf1, 'newcontent')
|
edit_content(dirf1, 'newcontent')
|
||||||
|
|
||||||
# add more file
|
# add more file
|
||||||
dirf2, _ = create_random_file(dpath)
|
_, _ = create_random_file(dpath)
|
||||||
|
|
||||||
# add more dirs
|
# add more dirs
|
||||||
dpath = os.path.join(dpath, get_string(5))
|
dpath = os.path.join(dpath, get_string(5))
|
||||||
@@ -149,36 +150,43 @@ class TestUpdate(unittest.TestCase):
|
|||||||
create_random_file(dpath)
|
create_random_file(dpath)
|
||||||
|
|
||||||
# update it
|
# update it
|
||||||
o.update_path = [d1, dir1]
|
opt.update_path = [d1, dir1]
|
||||||
cmd_update(o)
|
cmd_update(opt)
|
||||||
|
|
||||||
# test content
|
# test content
|
||||||
newcontent = open(d1, 'r').read()
|
newcontent = ''
|
||||||
|
with open(d1, 'r', encoding='utf-8') as file:
|
||||||
|
newcontent = file.read()
|
||||||
self.assertTrue(newcontent == 'newcontent')
|
self.assertTrue(newcontent == 'newcontent')
|
||||||
newcontent = open(dirf1, 'r').read()
|
newcontent = ''
|
||||||
|
with open(dirf1, 'r', encoding='utf-8') as file:
|
||||||
|
newcontent = file.read()
|
||||||
self.assertTrue(newcontent == 'newcontent')
|
self.assertTrue(newcontent == 'newcontent')
|
||||||
|
|
||||||
edit_content(d2, 'newcontentbykey')
|
edit_content(d2, 'newcontentbykey')
|
||||||
|
|
||||||
# update it by key
|
# update it by key
|
||||||
dfiles = o.dotfiles
|
dfiles = opt.dotfiles
|
||||||
d2key = ''
|
d2key = ''
|
||||||
for ds in dfiles:
|
for dotfile in dfiles:
|
||||||
t = os.path.expanduser(ds.dst)
|
src = os.path.expanduser(dotfile.dst)
|
||||||
if t == d2:
|
if src == d2:
|
||||||
d2key = ds.key
|
d2key = dotfile.key
|
||||||
break
|
break
|
||||||
self.assertTrue(d2key != '')
|
self.assertTrue(d2key != '')
|
||||||
o.update_path = [d2key]
|
opt.update_path = [d2key]
|
||||||
o.update_iskey = True
|
opt.update_iskey = True
|
||||||
cmd_update(o)
|
cmd_update(opt)
|
||||||
|
|
||||||
# test content
|
# test content
|
||||||
newcontent = open(d2, 'r').read()
|
newcontent = ''
|
||||||
|
with open(d2, 'r', encoding='utf-8') as file:
|
||||||
|
newcontent = file.read()
|
||||||
self.assertTrue(newcontent == 'newcontentbykey')
|
self.assertTrue(newcontent == 'newcontentbykey')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user