From a9b2fbfecc8ed6187a6f09b17b4cffb82f2126f2 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Thu, 15 Nov 2018 18:27:45 +0100 Subject: [PATCH] adding unittest for listing commands --- tests/test_listings.py | 100 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/test_listings.py diff --git a/tests/test_listings.py b/tests/test_listings.py new file mode 100644 index 0000000..3f757a3 --- /dev/null +++ b/tests/test_listings.py @@ -0,0 +1,100 @@ +""" +author: deadc0de6 (https://github.com/deadc0de6) +Copyright (c) 2017, deadc0de6 +basic unittest for the compare function +""" + + +import unittest +import os +import yaml + +from dotdrop.config import Cfg +from dotdrop.dotdrop import cmd_list_profiles +from dotdrop.dotdrop import cmd_list_files +from dotdrop.dotdrop import cmd_detail +from dotdrop.dotdrop import cmd_importer + +from tests.helpers import * + + +class TestListings(unittest.TestCase): + + CONFIG_BACKUP = False + CONFIG_CREATE = True + CONFIG_DOTPATH = 'dotfiles' + CONFIG_NAME = 'config.yaml' + + def test_listings(self): + '''Test the compare function''' + # 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_tempdir() + create_dir(fold_tmp) + self.addCleanup(clean, fold_tmp) + + # create the directories + tmp = get_tempdir() + self.assertTrue(os.path.exists(tmp)) + self.addCleanup(clean, tmp) + + dotfilespath = get_tempdir() + self.assertTrue(os.path.exists(dotfilespath)) + self.addCleanup(clean, dotfilespath) + + # create the dotfiles to test + d1, c1 = create_random_file(fold_config) + self.assertTrue(os.path.exists(d1)) + self.addCleanup(clean, d1) + d2, c2 = create_random_file(fold_subcfg) + self.assertTrue(os.path.exists(d2)) + self.addCleanup(clean, d2) + d3, c3 = create_random_file(fold_tmp) + self.assertTrue(os.path.exists(d3)) + self.addCleanup(clean, d3) + d4, c4 = create_random_file(fold_tmp, binary=True) + self.assertTrue(os.path.exists(d4)) + self.addCleanup(clean, d4) + d5 = get_tempdir() + self.assertTrue(os.path.exists(d5)) + self.addCleanup(clean, d5) + d6, _ = create_random_file(d5) + self.assertTrue(os.path.exists(d6)) + + # create the config file + profile = get_string(5) + confpath = create_fake_config(dotfilespath, + configname=self.CONFIG_NAME, + dotpath=self.CONFIG_DOTPATH, + backup=self.CONFIG_BACKUP, + create=self.CONFIG_CREATE) + self.assertTrue(os.path.exists(confpath)) + conf, opts = load_config(confpath, profile) + dfiles = [d1, d2, d3, d4, d5] + + # import the files + cmd_importer(opts, conf, dfiles) + conf, opts = load_config(confpath, profile) + + # listfiles + cmd_list_profiles(conf) + + # list files + cmd_list_files(opts, conf, templateonly=False) + cmd_list_files(opts, conf, templateonly=True) + + # details + cmd_detail(opts, conf, keys=None) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main()