...
 
Commits (2)
......@@ -208,6 +208,7 @@ def help(cb=None):
cb = Callback.factory(cb or context.default_module)
def _modhelp():
moddoc = False
if cb.filename:
moddoc = filedoc(cb.filename)
......
import unittest
"""Clitoo Test cases."""
import clitoo
import sys
import os
import shutil
import pytest
class ContextTest(unittest.TestCase):
"""Test cases for Context class and method."""
class TestClitoo(object):
"""Classes can still be used to organize collections of test cases, with.
def setUp(self):
"""Setup initial data for the test."""
self.argvList = ['-a', '--b', '--something=to see', 'how', 'it=parses']
self.ct = clitoo.Context.factory(self.argvList)
each test being a Method on the Class, rather than a standalone function.
"""
def test_factory(self):
"""Test aggument and keyword argument for factory."""
self.assertDictEqual({'something': 'to see'}, self.ct.kwargs)
self.assertListEqual(['a', 'b'], self.ct.args)
url = "https://yourlabs.io/oss/clitoo.git"
def test_python_3_version_compatibility(self):
"""Test python 3 version comptibility."""
pyvestion = sys.version.split(".")
assert pyvestion[0] == '3' and pyvestion[1] == '6'
class CallbackTest(unittest.TestCase):
"""Test cases for callback class and method."""
def test_python_2_version_compatibility(self):
"""Test python 2 version comptibility."""
pyvestion = sys.version.split(".")
assert pyvestion[0] != '2'
def test_context_valid_args_factory(self):
"""Test aggument and keyword argument for factory."""
argvlist = ['-a', '--b', '--something=to see', 'how', 'it=parses']
ct = clitoo.Context.factory(argvlist)
assert set({'something': 'to see'}).issubset(ct.kwargs)
assert set(['a', 'b']).issubset(ct.args)
def test_context_invalid_single_dash_kwargs_factory(self):
"""Test single dash keyword argument for context factory."""
argvlist = ['-a', '--b', '--something=-', 'how', 'it=-parses']
with pytest.raises(OSError):
print(clitoo.Context.factory(argvlist))
def test_context_invalid_double_dash_argument_factory(self):
"""Test aggument and keyword argument for factory."""
argvlist = ['-a', '--b', '--', '--something=to see', 'how', 'it=parses']
with pytest.raises(OSError):
print(clitoo.Context.factory(argvlist))
def test_expand_invalid_single_dash_argument_factory(self):
"""Test invalid argument format for the expand."""
argvlist = ['your.func', '-a', '-', '--b', '--something=to see', 'how',
'it=parses']
with pytest.raises(OSError):
print(clitoo.expand(*argvlist[1:]))
def test_context_empty_factory(self):
"""Test aggument and keyword argument for factory."""
argvlist = []
ct = clitoo.Context.factory(argvlist)
assert set({}).issubset(ct.kwargs)
assert set([]).issubset(ct.args)
def test_factory(self):
"""
Test pass for avaliable callback.
"""Test pass for avaliable callback.
Test nested attribute for factory.
"""
from clitoo.git import clone, push, apply
cb = clitoo.Callback.factory('clitoo.git.clone')
self.assertEqual(cb.cb, clone)
assert cb.cb == clone
cb = clitoo.Callback.factory('clitoo.git.push')
self.assertEqual(cb.cb, push)
assert cb.cb == push
cb = clitoo.Callback.factory('clitoo.git.apply')
self.assertEqual(cb.cb, apply)
assert cb.cb == apply
def test_factory_fail(self):
"""
Test fail for not avaliable callback and nested attribute for factory.
"""
"""Test fail for not avaliable callback and nested attribute for factory."""
cb = clitoo.Callback.factory('clitoo.git.reset')
self.assertEqual(cb.cb, None)
def test_filename(self):
"""Test filename."""
pass
assert cb.cb is None
def test_callback_fail(self):
"""Test fail for not avaliable callback."""
......@@ -54,24 +87,14 @@ class CallbackTest(unittest.TestCase):
def test_callback_callables(self):
"""The test success, If the callback is available."""
cb = clitoo.Callback.factory('clitoo.help')
self.assertIn('help', cb.callables)
self.assertIn('debug', cb.callables)
class ClitooTest(unittest.TestCase):
"""Test properties of class and methods."""
def setUp(self):
"""Setup initial data for the test."""
self.argvList = ['your.func', '-a', '--b', '--something=to see', 'how',
'it=parses']
self.ct = clitoo.Context.factory(self.argvList)
self.ex_args, self.ex_kwargs = clitoo.expand(*self.argvList[1:])
assert 'help' in cb.callables
assert 'debug' in cb.callables
def test_class_properties(self):
"""
Checks class didnt change from a defined snapshot. Class changes or new
references makes this test fail to warn the dev, who will decide if the
Check class didnt change from a defined snapshot. Class changes or new.
references makes this test fail to warn the dev, who will decide if the.
change must be accounted.
"""
def _check_class_properties(model_class, properties_list_snapshot):
......@@ -79,14 +102,7 @@ class ClitooTest(unittest.TestCase):
fields = [field for field, _ in model_class.__dict__.items()]
missing_list = set(properties_list_snapshot) - set(fields)
new_list = set(fields) - set(properties_list_snapshot)
self.assertTrue(
len(missing_list) == 0 and len(new_list) == 0,
'Model {} changed from its snapshot. Check if the modification'
' has to be accounted for in the duplication and update the '
'snapshot. New elements: {}. Missing elements: {}.'.format(
model_class.__class__, ', '.join(new_list)
if new_list else 'none', ', '.join(missing_list)
if missing_list else 'none'))
assert len(missing_list) == 0 and len(new_list) == 0
callback_props = ['path', 'module', 'modname', 'funcname', 'parts',
'cb', 'callables']
......@@ -97,21 +113,75 @@ class ClitooTest(unittest.TestCase):
def test_expand(self):
"""Test format of the argument and keyword argument to expanding."""
self.assertListEqual(self.ex_args, ['how'])
self.assertDictEqual(self.ex_kwargs, {'it': 'parses'})
argvlist = ['your.func', '-a', '--b', '--something=to see', 'how',
'it=parses']
ex_args, ex_kwargs = clitoo.expand(*argvlist[1:])
assert set(ex_args).issubset(['how'])
assert set(ex_kwargs).issubset({'it': 'parses'})
def test_filenamne(self):
"""Test filename of callback function."""
cb = clitoo.Callback.factory('help')
assert len(cb.filename) != 0
def test_no_filedoc(self):
"""Return default doc string.If doc string is not avaliable for followling(clone,push,)."""
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
file_path = base_dir + '/clitoo/clitoo/git.py'
doc_text = clitoo.filedoc(file_path)
assert 'Document me !' == doc_text
def test_main(self):
"""Test main method."""
clitoo.main(['debug', 'git.clone'])
def test_run_cmd(self):
"""Test _run function of the git module."""
base_dir = os.path.dirname(os.path.abspath(__file__))
app_path = base_dir + "/clitoo/testcli"
cmd = ['clone', self.url]
cmd.append(app_path)
clitoo.git._run(cmd)
assert os.path.isdir(app_path)
shutil.rmtree(app_path)
def test_clone_cmd(self):
"""Test clone of the git module."""
base_dir = os.path.dirname(os.path.abspath(__file__))
clitoo.git.clone(self.url, base_dir + "/clitoo/testcli")
assert os.path.isdir(base_dir + "/clitoo/testcli/clitoo")
shutil.rmtree(base_dir + "/clitoo/testcli")
def test_apply_cmd(self):
"""Test apply of the git module."""
clitoo.git.apply()
def test_apply_help_cmd(self):
"""Return the help doc string for the apply."""
clitoo.help('git.apply')
def test_push_help_cmd(self):
"""Return the help doc string for the push."""
clitoo.help('git.push')
def test_reset_help_cmd(self):
"""Return the help doc string for the clone."""
with pytest.raises(AttributeError):
print(clitoo.help('git.reset'))
def test_help(self):
"""Test help method."""
pass
clitoo.help()
def test_filedoc(self):
"""Test filedoc method."""
pass
def test_debug(self):
def test_empty_debug(self):
"""Test debug method."""
pass
clitoo.debug()
def test_args_debug(self):
"""Test debug method."""
clitoo.debug(*('git.clone', '12'))
if __name__ == '__main__':
unittest.main()
def test_not_exists_method(self):
"""Test not avaliable method for clitoo module."""
with pytest.raises(AttributeError):
print(clitoo.exists())