mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 05:39:43 +00:00
refactor and linting
This commit is contained in:
@@ -21,6 +21,42 @@ from dotdrop.utils import header
|
||||
from dotdrop.linktypes import LinkTypes
|
||||
|
||||
|
||||
def fake_config(path, dotfiles, profile,
|
||||
dotpath, actions, transs):
|
||||
"""Create a fake config file"""
|
||||
with open(path, 'w', encoding='utf-8') as file:
|
||||
file.write('actions:\n')
|
||||
for action in actions:
|
||||
file.write(f' {action.key}: {action.action}\n')
|
||||
file.write('trans:\n')
|
||||
for trans in transs:
|
||||
file.write(f' {trans.key}: {trans.action}\n')
|
||||
file.write('config:\n')
|
||||
file.write(' backup: true\n')
|
||||
file.write(' create: true\n')
|
||||
file.write(f' dotpath: {dotpath}\n')
|
||||
file.write('dotfiles:\n')
|
||||
for dotfile in dotfiles:
|
||||
linkval = dotfile.link.name.lower()
|
||||
file.write(f' {dotfile.key}:\n')
|
||||
file.write(f' dst: {dotfile.dst}\n')
|
||||
file.write(f' src: {dotfile.src}\n')
|
||||
file.write(f' link: {linkval}\n')
|
||||
if len(dotfile.actions) > 0:
|
||||
file.write(' actions:\n')
|
||||
for action in dotfile.actions:
|
||||
file.write(f' - {action.key}\n')
|
||||
if dotfile.trans_r:
|
||||
for trans in dotfile.trans_r:
|
||||
file.write(f' trans_read: {trans.key}\n')
|
||||
file.write('profiles:\n')
|
||||
file.write(f' {profile}:\n')
|
||||
file.write(' dotfiles:\n')
|
||||
for dotfile in dotfiles:
|
||||
file.write(f' - {dotfile.key}\n')
|
||||
return path
|
||||
|
||||
|
||||
class TestInstall(unittest.TestCase):
|
||||
"""test case"""
|
||||
|
||||
@@ -39,41 +75,6 @@ exec bspwm
|
||||
exec bspwm
|
||||
'''
|
||||
|
||||
def fake_config(self, path, dotfiles, profile,
|
||||
dotpath, actions, transs):
|
||||
"""Create a fake config file"""
|
||||
with open(path, 'w', encoding='utf-8') as file:
|
||||
file.write('actions:\n')
|
||||
for action in actions:
|
||||
file.write(f' {action.key}: {action.action}\n')
|
||||
file.write('trans:\n')
|
||||
for trans in transs:
|
||||
file.write(f' {trans.key}: {trans.action}\n')
|
||||
file.write('config:\n')
|
||||
file.write(' backup: true\n')
|
||||
file.write(' create: true\n')
|
||||
file.write(f' dotpath: {dotpath}\n')
|
||||
file.write('dotfiles:\n')
|
||||
for dotfile in dotfiles:
|
||||
linkval = dotfile.link.name.lower()
|
||||
file.write(f' {dotfile.key}:\n')
|
||||
file.write(f' dst: {dotfile.dst}\n')
|
||||
file.write(f' src: {dotfile.src}\n')
|
||||
file.write(f' link: {linkval}\n')
|
||||
if len(dotfile.actions) > 0:
|
||||
file.write(' actions:\n')
|
||||
for action in dotfile.actions:
|
||||
file.write(f' - {action.key}\n')
|
||||
if dotfile.trans_r:
|
||||
for trans in dotfile.trans_r:
|
||||
file.write(f' trans_read: {trans.key}\n')
|
||||
file.write('profiles:\n')
|
||||
file.write(f' {profile}:\n')
|
||||
file.write(' dotfiles:\n')
|
||||
for dotfile in dotfiles:
|
||||
file.write(f' - {dotfile.key}\n')
|
||||
return path
|
||||
|
||||
def test_install(self):
|
||||
"""Test the install function"""
|
||||
|
||||
@@ -186,8 +187,8 @@ exec bspwm
|
||||
dotfiles = [dotfile1, dotfile2, dotfile3, dotfile4,
|
||||
dotfile5, dotfile6, dotfile7, dotfile8,
|
||||
dotfile9, dotfile10, ddot]
|
||||
self.fake_config(confpath, dotfiles,
|
||||
profile, tmp, [act1], [the_trans])
|
||||
fake_config(confpath, dotfiles,
|
||||
profile, tmp, [act1], [the_trans])
|
||||
conf = Cfg(confpath, profile, debug=True)
|
||||
self.assertTrue(conf is not None)
|
||||
|
||||
|
||||
@@ -14,6 +14,24 @@ from dotdrop.dotfile import Dotfile
|
||||
from dotdrop.dotdrop import cmd_install
|
||||
|
||||
|
||||
def fake_config(path, dotfile, profile, dotpath):
|
||||
"""Create a fake config file"""
|
||||
with open(path, 'w', encoding='utf-8') as file:
|
||||
file.write('config:\n')
|
||||
file.write(' backup: true\n')
|
||||
file.write(' create: true\n')
|
||||
file.write(f' dotpath: {dotpath}\n')
|
||||
file.write('dotfiles:\n')
|
||||
file.write(f' {dotfile.key}:\n')
|
||||
file.write(f' dst: {dotfile.dst}\n')
|
||||
file.write(f' src: {dotfile.src}\n')
|
||||
file.write('profiles:\n')
|
||||
file.write(f' {profile}:\n')
|
||||
file.write(' dotfiles:\n')
|
||||
file.write(f' - {dotfile.key}\n')
|
||||
return path
|
||||
|
||||
|
||||
class TestJhelpers(unittest.TestCase):
|
||||
"""test case"""
|
||||
|
||||
@@ -56,23 +74,6 @@ basename: c
|
||||
dirname: /tmp/a/b
|
||||
'''
|
||||
|
||||
def fake_config(self, path, dotfile, profile, dotpath):
|
||||
"""Create a fake config file"""
|
||||
with open(path, 'w', encoding='utf-8') as file:
|
||||
file.write('config:\n')
|
||||
file.write(' backup: true\n')
|
||||
file.write(' create: true\n')
|
||||
file.write(f' dotpath: {dotpath}\n')
|
||||
file.write('dotfiles:\n')
|
||||
file.write(f' {dotfile.key}:\n')
|
||||
file.write(f' dst: {dotfile.dst}\n')
|
||||
file.write(f' src: {dotfile.src}\n')
|
||||
file.write('profiles:\n')
|
||||
file.write(f' {profile}:\n')
|
||||
file.write(' dotfiles:\n')
|
||||
file.write(f' - {dotfile.key}\n')
|
||||
return path
|
||||
|
||||
def test_jhelpers(self):
|
||||
"""Test the install function"""
|
||||
|
||||
@@ -96,7 +97,7 @@ dirname: /tmp/a/b
|
||||
# generate the config and stuff
|
||||
profile = get_string(5)
|
||||
confpath = os.path.join(tmp, self.CONFIG_NAME)
|
||||
self.fake_config(confpath, dotfile1, profile, tmp)
|
||||
fake_config(confpath, dotfile1, profile, tmp)
|
||||
conf = CfgAggregator(confpath, profile, debug=True)
|
||||
self.assertTrue(conf is not None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user