Conghao97's picture tcftrees's picture
ProgramGen release
d086025
Raw History Blame Contribute Delete
16.7 kB
diff --git a/UnitTesting/test_parser.py b/UnitTesting/test_parser.py
new file mode 100644
--- /dev/null
+++ b/UnitTesting/test_parser.py
@@ -0,0 +1,115 @@
+from unittest import TestCase
+
+import os
+
+from PyProjManCore.proj_man import ProjMan
+from PyProjManUI.parser import PyProjManParser, OpCode
+
+
+def helper_load_cfg_file():
+ print(os.path.join('PyProjMan','UnitTesting', 'test.json'))
+ #p = PyProjManParser(config_file=os.path.join(os.getcwd(), 'test.json'))
+ p = PyProjManParser(config_file = os.path.join(os.getcwd(),'PyProjManUI','data', 'parser.json'))
+ return p
+
+
+class TestPyProjManParser(TestCase):
+ """Test PyProjManParser"""
+ def test_init(self):
+ """Can we define a PyProjManParserobject?"""
+ p = helper_load_cfg_file()
+ self.assertIsInstance(p, PyProjManParser)
+
+ def test_load_parser_data_version(self):
+ """Can read Version from Config file"""
+ p = helper_load_cfg_file()
+ target = '0.0.3'
+ self.assertEqual(target,p._version)
+
+ def test_load_parser_data_release(self):
+ """Can read Release from Config file"""
+ p = helper_load_cfg_file()
+ target = 'alpha'
+ self.assertEqual(target,p._release)
+
+ def test_load_parser_data_ignore_case(self):
+ """Can read Ignore Case from Config file"""
+ p = helper_load_cfg_file()
+ target = True
+ self.assertEqual(target, p._ignore_case)
+
+ def test_load_parser_data_primitives(self):
+ """Can read Primitives from Config file"""
+ p = helper_load_cfg_file()
+ target = {"ADD": 256}
+ key = 'ADD'
+ value = 256
+ target = {key: value}
+ self.assertEqual(target[key], p._primitives[key])
+
+ def test_load_parser_data_verbs(self):
+ """Can read Verbs from Config file"""
+ p = helper_load_cfg_file()
+ target = {"add": "ADD"}
+ key = 'add'
+ value = 'ADD'
+ target = {key: value}
+ self.assertEqual(target[key], p._verbs[key])
+
+ def test_load_parser_data_parameters(self):
+ """Can read Parameters from Config file"""
+ p = helper_load_cfg_file()
+ key = 'best'
+ value = 'BEST'
+ target = {key: value}
+ self.assertEqual(target[key], p._parameters[key])
+
+
+ def test_load_parser_data_decorators(self):
+ """Can read Decorators from Config file"""
+ p = helper_load_cfg_file()
+ key = 'on'
+ value = 'ON'
+ target = {key: value}
+ self.assertEqual(target[key], p._decorators[key])
+
+ def test_load_parser_data_reply(self):
+ """Can read Reply from Config file"""
+ p = helper_load_cfg_file()
+ key = 200
+ value = 'Bye'
+ target = {key: value}
+ print(p._reply[key])
+ self.assertEqual(target[key], p._reply[key])
+
+ def test_load_parser_data_err_codes(self):
+ """Can read Error Codes from Config file"""
+ p = helper_load_cfg_file()
+ key = 100
+ value = 'Success'
+ target = {key: value}
+ self.assertEqual(target[key], p._error_codes[key])
+
+ def test_parse_create_project_verb(self):
+ """Parse input string of create project (Verb)"""
+ p = helper_load_cfg_file()
+ op_code = p.parse("CREATE PROJECT [Test Project]")
+ target = p._primitives['CREATE']
+ self.assertEqual(op_code._verb, target)
+
+ def test_parse_create_project_parameters(self):
+ """Parse input string of create project (Parameters)"""
+ p = helper_load_cfg_file()
+ op_code = p.parse("CREATE PROJECT [Test Project]")
+ target = p._primitives['PROJECT']
+ self.assertIn(target,op_code._inp_params)
+
+ def test_parse_create_project_realization(self):
+ """Parse input string of create project (Creates the project)"""
+ p = helper_load_cfg_file()
+ project_name = "Test Project"
+ op_code = p.parse("CREATE PROJECT [{}]".format(project_name))
+ print(op_code)
+ op_code = p.hook(op_code)
+ print(op_code)
+ self.assertEqual(p._project.name, project_name)
diff --git a/UnitTesting/test_proj_man.py b/UnitTesting/test_proj_man.py
new file mode 100644
--- /dev/null
+++ b/UnitTesting/test_proj_man.py
@@ -0,0 +1,97 @@
+from unittest import TestCase
+from PyProjManCore.proj_man import ProjMan
+from PyProjManCore.task import Task
+
+
+class TestProjMan(TestCase):
+ def test_init(self):
+ """Check Type of ProjMan"""
+ pm = ProjMan()
+ self.assertIsInstance(pm, ProjMan)
+
+ def test_root(self):
+ """Can create a new project with a root Task"""
+ root = Task("Root Task")
+ pm = ProjMan(root)
+ self.assertEqual(root, pm.root)
+
+ def test_name(self):
+ """Can we define a name in the constructor?"""
+ project_name = "Some Project Name"
+ pm = ProjMan(None, project_name)
+ self.assertEqual(project_name, pm.name)
+
+ def test_add_child(self):
+ """PM Can add a child"""
+ root = Task("Root Task")
+ pm = ProjMan(root)
+ child = Task("Child Task")
+ pm.add_child(child)
+ self.assertIn(child, root.dependants)
+
+ def test_add_child2(self):
+ """PM Adding a child implies root is a parent for the child"""
+ root = Task("Root Task")
+ pm = ProjMan(root)
+ child = Task("Child Task")
+ pm.add_child(child)
+ self.assertIn(root, child.prerequisites)
+
+ def test_add_parent(self):
+ """Can Add Parent to Root Task"""
+ root = Task("Root Task")
+ pm = ProjMan(root)
+ parent = Task("Parent Task")
+ pm.add_parent(parent)
+ self.assertIn(parent, root.prerequisites)
+
+ def test_add_parent_rebase1(self):
+ """Adding Parent to root Task, Rebase Root to Parent"""
+ root = Task("Root Task")
+ pm = ProjMan(root)
+ parent = Task("Parent Task")
+ pm.add_parent(parent)
+ self.assertEqual(parent, pm.root)
+
+ def test_add_parent_rebase2(self):
+ """Adding Parent to root Task, Makes former root a child to parent"""
+ root = Task("Root Task")
+ pm = ProjMan(root)
+ parent = Task("Parent Task")
+ pm.add_parent(parent)
+ self.assertIn(root, pm.root.dependants)
+
+ def test_list_tasks(self):
+ """Listing all tasks in a project"""
+ # Create Root
+ root = Task("Root Task")
+ # Create Project
+ pm = ProjMan(root)
+ # Append Children
+ child1 = Task("Child Task 1")
+ pm.add_child(child1)
+
+ child2 = Task("Child Task 2")
+ pm.add_child(child2)
+
+ task_list = pm.list_tasks()
+ self.assertTrue(
+ root in task_list and
+ child1 in task_list and
+ child2 in task_list)
+
+ def test_list_tasks_duplicates(self):
+ """Listing all tasks in a project, no duplicates"""
+ # Create Root
+ root = Task("Root Task")
+ # Create Project
+ pm = ProjMan(root)
+ # Append Children
+ child1 = Task("Child Task 1")
+ pm.add_child(child1)
+
+ child2 = Task("Child Task 2")
+ pm.add_child(child2)
+
+ task_list = pm.list_tasks()
+ self.assertEqual(3, len(task_list))
diff --git a/UnitTesting/test_proj_stats.py b/UnitTesting/test_proj_stats.py
new file mode 100644
--- /dev/null
+++ b/UnitTesting/test_proj_stats.py
@@ -0,0 +1,68 @@
+from datetime import timedelta
+from unittest import TestCase
+
+from PyProjManCore.proj_stats import ProjStats
+from PyProjManCore.task import Task
+
+
+class TestProjStats(TestCase):
+ def test_init(self):
+ stat = ProjStats()
+ self.assertIsInstance(stat, ProjStats)
+
+ def test_name_constructor(self):
+ name = "Project Name"
+ stat = ProjStats(name)
+ self.assertEqual(name, stat.name)
+
+ def test_name_attribute(self):
+ name = "Project Name"
+ stat = ProjStats()
+ stat.name = name
+ self.assertEqual(name, stat.name)
+
+ def test_first(self):
+ stat = ProjStats()
+ first = Task("First")
+ stat.first = first
+ self.assertEqual(first, stat.first)
+
+ def test_last(self):
+ stat = ProjStats()
+ last = Task("Last")
+ stat.first = last
+ self.assertEqual(last, stat.first)
+
+ def test_count(self):
+ stat = ProjStats()
+ count = 5
+ stat.count = count
+ self.assertEqual(count, stat.count)
+
+ def test_duration(self):
+ stat = ProjStats()
+ duration = timedelta(days=5, hours=10, minutes=3)
+ stat.duration = duration
+ self.assertEqual(duration, stat.duration)
+
+ def test_tasks_list(self):
+ stat = ProjStats()
+ tasks = ["Task 1", "Task 2", "Task 3"]
+ stat.tasks = tasks
+ self.assertListEqual(tasks, stat.tasks)
+
+ def test_append_to_tasks(self):
+ stat = ProjStats()
+ tasks = ["Task 1", "Task 2", "Task 3"]
+ stat.tasks = tasks
+ new_task = "New Task"
+ stat.append_task(new_task)
+ self.assertIn(new_task, stat.tasks)
+
+ def test_delete_from_tasks(self):
+ stat = ProjStats()
+ tasks = ["Task 1", "Task 2", "Task 3"]
+ stat.tasks = tasks
+ removed_task = "Task 2"
+ stat.remove_task(removed_task)
+ self.assertNotIn(removed_task, stat.tasks)
diff --git a/UnitTesting/test_task.py b/UnitTesting/test_task.py
new file mode 100644
--- /dev/null
+++ b/UnitTesting/test_task.py
@@ -0,0 +1,73 @@
+from datetime import datetime
+from unittest import TestCase
+from PyProjManCore.task import Task
+from PyProjManCore.time_element import TimeElement
+
+
+class TestTaskParameters(TestCase):
+ """Test Fields of Task Object"""
+ def test_id(self):
+ """Check if Task ID has UUID Version 4"""
+ t = Task()
+ expected = 4
+ self.assertEqual(expected, t.id.version)
+
+ def test_name(self):
+ """Test Task Name Property Setter and Getter"""
+ expected = 'Task'
+ t = Task(expected)
+ t.name = expected
+ self.assertEqual(t.name, expected, t.name)
+
+ def test_planned_dates(self):
+ """Define planned start date"""
+ expected = datetime(year=2017, month=11, day=30)
+ planned = TimeElement()
+ planned.start = expected
+ t = Task("Sample Task")
+ t.planned = planned
+ self.assertEqual(expected, t.planned.start)
+
+ def test_actual_dates(self):
+ """Define actual start date"""
+ expected = datetime(year=2017, month=11, day=30)
+ actual = TimeElement()
+ actual.start = expected
+ t = Task("Sample Task")
+ t.actual = actual
+ self.assertEqual(expected, t.actual.start)
+
+ def test_prerequisites(self):
+ """
+ Create a list of tasks
+ Create a single task
+ Assign list of tasks to the single task
+ """
+ target = Task()
+ prereqs = []
+ for i in range(10):
+ p = Task("Super-task {}".format(i))
+ prereqs.append(p)
+ target.prerequisites = prereqs
+ self.assertEqual(prereqs, target.prerequisites)
+
+ def test_dependants(self):
+ """
+ Create a task
+ Create a set of tasks
+ set set of tasks as dependants of the first task
+ """
+ target = Task()
+ dependants = []
+ for i in range(10):
+ d = Task("Sub-task {}".format(i))
+ dependants.append(d)
+ target.dependants = dependants
+ self.assertEqual(dependants, target.dependants)
+
+ def test_completed(self):
+ """Test Task completion percentage"""
+ t = Task()
+ expected = 0.5
+ t.completed = expected
+ self.assertEqual(expected, t.completed)
diff --git a/UnitTesting/test_task_exceptions.py b/UnitTesting/test_task_exceptions.py
new file mode 100644
--- /dev/null
+++ b/UnitTesting/test_task_exceptions.py
@@ -0,0 +1,29 @@
+from unittest import TestCase
+
+from PyProjManCore.task import Task
+
+
+class TestTaskOperationsExceptions(TestCase):
+ """Test Exceptions for Task operations"""
+ def test_append_duplicate_prereq(self):
+ """Test appending duplicate prerequisites to a task, it should be unique"""
+ root = Task("Root Task")
+ parent = Task("Parent Task")
+ root.append_prerequisite(parent)
+ root.append_prerequisite(parent)
+ self.assertNotEqual(2, len(root.prerequisites))
+
+ def test_cyclic_dependency(self):
+ """
+ Test case of a cyclic dependency, i.e. a Task depends on itself,
+ or a task has both prerequisite and child the same
+ """
+ self.fail("Not implemented ")
+
+ def test_append_duplicate_dep(self):
+ """Test appending duplicate dependants to a task, it should be unique"""
+ root = Task("Root Task")
+ child = Task("Child Task")
+ root.append_dependant(child)
+ root.append_dependant(child)
+ self.assertNotEqual(2, len(root.dependants))
diff --git a/UnitTesting/test_task_happy.py b/UnitTesting/test_task_happy.py
new file mode 100644
--- /dev/null
+++ b/UnitTesting/test_task_happy.py
@@ -0,0 +1,27 @@
+from unittest import TestCase
+
+from PyProjManCore.task import Task
+
+
+class TestTaskOperationsHappyPath(TestCase):
+ """Test Basic Operations of a task, in the happy path"""
+ def test_append_prereq(self):
+ """
+ Create a Task
+ Create another task and append it to prerequisites of first task
+ """
+ target = Task()
+ prereq = Task()
+ target.prerequisites.append(prereq)
+ self.assertIn(prereq, target.prerequisites)
+
+ def test_append_dependants(self):
+ """
+ Create a Task
+ Create a second task
+ Append second task to first task's list of dependants
+ """
+ target = Task()
+ dep = Task()
+ target.append_dependant(dep)
+ self.assertIn(dep, target.dependants)
diff --git a/UnitTesting/test.json b/UnitTesting/test.json
new file mode 100644
--- /dev/null
+++ b/UnitTesting/test.json
@@ -0,0 +1,108 @@
+{
+ "FileDescription": "PyProjMan Keyword Dictionary",
+ "Version":"0.0.2",
+ "Release":"alpha",
+ "IgnoreCase":true,
+ "Primitives" : {
+ "ADD": "0x100",
+ "ADVICE": "0x110",
+ "ASSIGN": "0x120",
+ "CREATE": "0x130",
+ "DELETE": "0x140",
+ "DEMOTE": "0x150",
+ "ESTIMATE": "0x160",
+ "LINK": "0x170",
+ "LIST": "0x180",
+ "PROMOTE": "0x190",
+ "REPORT": "0x1a0",
+ "DISPLAY": "0x1b0",
+ "SUMMARY": "0x1c0",
+ "EXIT": "0x200",
+ "MANUAL": "0x210",
+ "LOAD": "0x220",
+ "SAVE": "0x230",
+ "SYNCHRONIZE": "0x240",
+ "ACTUAL": "0x300",
+ "BEST": "0x310",
+ "DATE": "0x320",
+ "MEAN": "0x330",
+ "FILE": "0x340",
+ "PROJECT": "0x350",
+ "STATUS": "0x360",
+ "TASK": "0x370",
+ "WORST": "0x380",
+ "ON": "0x400",
+ "TO": "0x410",
+ "FROM": "0x420",
+ "SUCCESS": "0x800",
+ "ERROR": "0x810"
+ },
+ "Verbs": {
+ "add": "ADD",
+ "adv": "ADVICE",
+ "advice": "ADVICE",
+ "assign": "ASSIGN",
+ "create": "CREATE",
+ "del": "DELETE",
+ "delete": "DELETE",
+ "dem": "DEMOTE",
+ "demote": "DEMOTE",
+ "disp": "DISPLAY",
+ "display": "DISPLAY",
+ "est": "ESTIMATE",
+ "estimate": "ESTIMATE",
+ "exit": "EXIT",
+ "help": "MANUAL",
+ "link": "LINK",
+ "list": "LIST",
+ "load": "LOAD",
+ "man": "MANUAL",
+ "manual": "MANUAL",
+ "open": "LOAD",
+ "promote": "PROMOTE",
+ "quit": "EXIT",
+ "remove": "DELETE",
+ "report": "REPORT",
+ "save": "SAVE",
+ "show": "DISPLAY",
+ "summary": "SUMMARY",
+ "sync": "SYNCHRONIZE",
+ "synchronize": "SYNCHRONIZE"
+ },
+ "Parameters":{
+ "best": "BEST",
+ "act": "ACTUAL",
+ "actual": "ACTUAL",
+ "dat": "DATE",
+ "date": "DATE",
+ "est": "MEAN",
+ "estimated": "MEAN",
+ "file": "FILE",
+ "planned": "MEAN",
+ "proj": "PROJECT",
+ "project": "PROJECT",
+ "stat": "STATUS",
+ "status": "STATUS",
+ "task": "TASK",
+ "worst": "WORST"
+ },
+ "Decorators" : {
+ "on": "ON",
+ "to": "TO",
+ "from": "FROM"
+ },
+ "Reply": {
+ "100": "Success",
+ "200": "Bye",
+ "999": ""
+ },
+ "ErrorCodes": {
+ "100": "Success",
+ "200": "Exiting!",
+ "300": "Pending",
+ "901": "Syntax Error",
+ "902": "Not Found",
+ "903": "Invalid Verb",
+ "999": "Failure"
+ }
+}