1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-08 05:39:15 +00:00

refactor folder to directory

This commit is contained in:
deadc0de6
2018-05-02 20:40:42 +02:00
parent b0847b2b4c
commit 927d76779f
7 changed files with 43 additions and 43 deletions

View File

@@ -16,7 +16,7 @@ TMPSUFFIX = '.dotdrop'
def clean(path):
'''Delete file or folder.'''
'''Delete file or directory.'''
if not os.path.exists(path):
return
if os.path.islink(path):
@@ -33,13 +33,13 @@ def get_string(length):
return ''.join(random.choice(alpha) for _ in range(length))
def get_tempfolder():
'''Get a temporary folder'''
def get_tempdir():
'''Get a temporary directory'''
return tempfile.mkdtemp(suffix=TMPSUFFIX)
def create_random_file(folder, content=None, binary=False):
'''Create a new file in folder with random content.'''
def create_random_file(directory, content=None, binary=False):
'''Create a new file in directory with random content.'''
fname = get_string(8)
mode = 'w'
if binary:
@@ -49,14 +49,14 @@ def create_random_file(folder, content=None, binary=False):
content = bytes(get_string(100), 'ascii')
else:
content = get_string(100)
path = os.path.join(folder, fname)
path = os.path.join(directory, fname)
with open(path, mode) as f:
f.write(content)
return path, content
def create_dir(path):
'''Create a folder'''
'''Create a directory'''
if not os.path.exists(path):
os.mkdir(path)
return path
@@ -93,10 +93,10 @@ def get_dotfile_from_yaml(dic, path):
return [d for d in dotfiles.values() if d['src'] == src][0]
def create_fake_config(folder, configname='config.yaml',
def create_fake_config(directory, configname='config.yaml',
dotpath='dotfiles', backup=True, create=True):
'''Create a fake config file'''
path = os.path.join(folder, configname)
path = os.path.join(directory, configname)
with open(path, 'w') as f:
f.write('config:\n')
f.write(' backup: %s\n' % (str(backup)))

View File

@@ -49,23 +49,23 @@ class TestCompare(unittest.TestCase):
def test_compare(self):
'''Test the compare function'''
# setup some folders
# setup some directories
fold_config = os.path.join(os.path.expanduser('~'), '.config')
create_dir(fold_config)
fold_subcfg = os.path.join(os.path.expanduser('~'), '.config',
get_string(5))
create_dir(fold_subcfg)
self.addCleanup(clean, fold_subcfg)
fold_tmp = get_tempfolder()
fold_tmp = get_tempdir()
create_dir(fold_tmp)
self.addCleanup(clean, fold_tmp)
# create the folders
tmp = get_tempfolder()
# create the directories
tmp = get_tempdir()
self.assertTrue(os.path.exists(tmp))
self.addCleanup(clean, tmp)
dotfilespath = get_tempfolder()
dotfilespath = get_tempdir()
self.assertTrue(os.path.exists(dotfilespath))
self.addCleanup(clean, dotfilespath)
@@ -82,7 +82,7 @@ class TestCompare(unittest.TestCase):
d4, c4 = create_random_file(fold_tmp, binary=True)
self.assertTrue(os.path.exists(d4))
self.addCleanup(clean, d4)
d5 = get_tempfolder()
d5 = get_tempdir()
self.assertTrue(os.path.exists(d5))
self.addCleanup(clean, d5)
d6, _ = create_random_file(d5)
@@ -120,7 +120,7 @@ class TestCompare(unittest.TestCase):
results = self.compare(opts, conf, tmp, len(dfiles))
self.assertTrue(results == expected)
# add file in folder
# add file in directory
d7, _ = create_random_file(d5)
self.assertTrue(os.path.exists(d7))
expected = {d1: False, d2: True, d3: True, d4: False, d5: False}

View File

@@ -25,7 +25,7 @@ class TestConfig(unittest.TestCase):
def test_config(self):
'''Test the config class'''
tmp = get_tempfolder()
tmp = get_tempdir()
self.assertTrue(os.path.exists(tmp))
self.addCleanup(clean, tmp)
@@ -48,7 +48,7 @@ class TestConfig(unittest.TestCase):
self.assertTrue(conf.dump() != '')
def test_include(self):
tmp = get_tempfolder()
tmp = get_tempdir()
self.assertTrue(os.path.exists(tmp))
self.addCleanup(clean, tmp)

View File

@@ -53,12 +53,12 @@ class TestImport(unittest.TestCase):
def test_import(self):
'''Test the import function'''
# on filesystem
src = get_tempfolder()
src = get_tempdir()
self.assertTrue(os.path.exists(src))
self.addCleanup(clean, src)
# in dotdrop
dotfilespath = get_tempfolder()
dotfilespath = get_tempdir()
self.assertTrue(os.path.exists(dotfilespath))
self.addCleanup(clean, dotfilespath)
@@ -87,8 +87,8 @@ class TestImport(unittest.TestCase):
dotfile4, content3 = create_random_file(homeconf)
self.addCleanup(clean, dotfile4)
# fake a folder containing dotfiles
dotfile5 = get_tempfolder()
# fake a directory containing dotfiles
dotfile5 = get_tempdir()
self.assertTrue(os.path.exists(dotfile5))
self.addCleanup(clean, dotfile5)
sub1, _ = create_random_file(dotfile5)
@@ -98,8 +98,8 @@ class TestImport(unittest.TestCase):
dotfile6, content6 = create_random_file(dotconfig)
self.addCleanup(clean, dotfile6)
# fake a folder for symlink
dotfile7 = get_tempfolder()
# fake a directory for symlink
dotfile7 = get_tempdir()
self.assertTrue(os.path.exists(dotfile7))
self.addCleanup(clean, dotfile7)
sub3, _ = create_random_file(dotfile7)
@@ -137,7 +137,7 @@ class TestImport(unittest.TestCase):
self.assert_in_yaml(dotfile6, y, link=True)
self.assert_in_yaml(dotfile7, y, link=True)
# test have been imported in dotdrop dotpath folder
# test have been imported in dotdrop dotpath directory
indt1 = os.path.join(dotfilespath,
self.CONFIG_DOTPATH,
get_path_strip_version(dotfile1))

View File

@@ -69,12 +69,12 @@ exec bspwm
'''Test the install function'''
# dotpath location
tmp = get_tempfolder()
tmp = get_tempdir()
self.assertTrue(os.path.exists(tmp))
self.addCleanup(clean, tmp)
# where dotfiles will be installed
dst = get_tempfolder()
dst = get_tempdir()
self.assertTrue(os.path.exists(dst))
self.addCleanup(clean, dst)
@@ -106,7 +106,7 @@ exec bspwm
self.addCleanup(clean, dst5)
d5 = Dotfile(get_string(6), dst5, os.path.basename(f5), link=True)
# create the dotfile folders in dotdrop
# create the dotfile directories in dotdrop
dir1 = create_dir(os.path.join(tmp, get_string(6)))
self.assertTrue(os.path.exists(dir1))
self.addCleanup(clean, dir1)
@@ -119,7 +119,7 @@ exec bspwm
# make up the dotfile
d6 = Dotfile(get_string(6), dst6, os.path.basename(dir1))
# to test symlink folders
# to test symlink directories
dir2 = create_dir(os.path.join(tmp, get_string(6)))
self.assertTrue(os.path.exists(dir2))
self.addCleanup(clean, dir2)