Coverage for tests/command/builder/test_command_queue.py: 100%

48 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-01-30 18:57 -0500

1"""Unit test file for command.builder.command_queue.py.""" 

2from src.probable_fiesta.command.builder import command_queue 

3from src.probable_fiesta.logger.logging_config import set_logger 

4 

5from logging import DEBUG 

6from unittest import TestCase 

7 

8# Create a logger 

9LOG = set_logger("test_command_queue", DEBUG) 

10 

11 

12class TestCommandBuilderCommandQueue(TestCase): 

13 

14 def setUp(self): 

15 self.command_queue = command_queue.CommandQueue() 

16 

17 def test_init(self): 

18 LOG.info("Test init") 

19 self.command_queue = command_queue.CommandQueue() 

20 self.assertEqual(self.command_queue.queue, []) 

21 

22 def test_add_new_command(self): 

23 LOG.info("Test add new command") 

24 function = lambda: "Hello World!" 

25 self.command_queue = command_queue.CommandQueue() 

26 self.command_queue.add_new_command("test", function, "--version") 

27 # test _str__ 

28 LOG.debug(str(self.command_queue)) 

29 exp = "CommandQueue: loaded commands: 1 executed commands: [] " 

30 self.assertEqual(str(self.command_queue), exp) 

31 

32 def test_show(self): 

33 LOG.info("Test show") 

34 function = lambda: "Hello World!" 

35 self.command_queue = command_queue.CommandQueue() 

36 self.command_queue.add_new_command("test", function, "--version") 

37 # test _str__ 

38 queue = self.command_queue.show() 

39 for command in queue: 

40 print(command) 

41 LOG.debug(str(queue)) 

42 self.assertEqual(len(queue), 1) 

43 

44 def test_run_all(self): 

45 LOG.info("Test run all") 

46 args = "--version" 

47 function = lambda x: (args) 

48 self.command_queue = command_queue.CommandQueue() 

49 self.command_queue.add_new_command("test1", function, args) 

50 self.command_queue.add_new_command("test2", function, args) 

51 self.command_queue.run_all() 

52 self.assertEqual(str(self.command_queue), "CommandQueue: loaded commands: 0 executed commands: ['--version', '--version'] ") 

53 

54 def test_get_history(self): 

55 LOG.info("Test get history") 

56 function = lambda x: (x) 

57 self.command_queue = command_queue.CommandQueue() 

58 self.command_queue.add_new_command("test1", function, "--test1") 

59 self.command_queue.add_new_command("test2", function, "--test2") 

60 self.command_queue.run_all() 

61 history = self.command_queue.get_history() 

62 self.assertEqual(history, ["--test1", "--test2"])