Esempio n. 1
0
 def test_file_on_path(self):
     """
     Test we do not crash if there is a file on the path, make sure it gets added
     """
     os.environ['PATH'] += ':~/.logria/sessions/.DS_Store'
     r = command_parser.Resolver()
     self.assertIn('.DS_Store', r._paths)
Esempio n. 2
0
 def test_path_folder_missing(self):
     """
     Test we do not crash if the folder does not exist
     """
     os.environ['PATH'] += ':/a/a/b/b/c/c/d/d'
     r = command_parser.Resolver()
     self.assertTrue(r._paths)
Esempio n. 3
0
 def test_resolve_file_as_list(self):
     """
     Test that we properly resolve a file to a list
     """
     r = command_parser.Resolver()
     actual = r.resolve_file_as_list('~/file.txt')
     expected = [f'{Path.home()}', 'file.txt']
     self.assertEqual(actual, expected)
Esempio n. 4
0
 def test_resolve_file_as_string(self):
     """
     Test that we properly resolve a file to a string
     """
     r = command_parser.Resolver()
     actual = r.resolve_file_as_str('$HOME/file.txt')
     expected = f'{Path.home()}/file.txt'
     self.assertEqual(actual, expected)
Esempio n. 5
0
 def test_resolve_home_dir(self):
     """
     Test that we resolve the proper strings to the user's home directory
     """
     r = command_parser.Resolver()
     expected = str(Path.home())
     self.assertEqual(r.resolve_home_dir('~'), expected)
     self.assertEqual(r.resolve_home_dir('$HOME'), expected)
Esempio n. 6
0
 def test_resolve_file_as_string(self):
     """
     Test that we properly resolve a file to a string
     """
     r = command_parser.Resolver()
     actual = r.resolve_command_as_string('$HOME/file.txt')
     expected = '/Users/chris/file.txt'
     self.assertEqual(actual, expected)
Esempio n. 7
0
 def test_no_path(self):
     """
     Test we do not crash if the path varibale is missing
     """
     path_string = os.environ.pop("PATH")
     r = command_parser.Resolver()
     self.assertFalse(r._paths)
     # Put the PATH back for other tests
     os.environ["PATH"] = path_string
Esempio n. 8
0
 def test_resolve_command_as_string(self):
     """
     Test that we properly resolve a command to a string
     """
     r = command_parser.Resolver()
     actual = r.resolve_command_as_string(
         'tail -f $HOME/file.txt | cat -ne')
     expected = f'/usr/bin/tail -f {Path.home()}/file.txt | /bin/cat -ne'
     self.assertEqual(actual, expected)
Esempio n. 9
0
 def test_resolve_command_as_string(self):
     """
     Test that we properly resolve a command to a string
     """
     r = command_parser.Resolver()
     actual = r.resolve_command_as_string(
         'tail -f $HOME/file.txt | grep [^a-z](.*?)<')
     expected = '/usr/bin/tail -f /Users/chris/file.txt | /usr/bin/grep [^a-z](.*?)<'
     self.assertEqual(actual, expected)
Esempio n. 10
0
 def test_resolve_command_as_list(self):
     """
     Test that we properly resolve a command to a list
     """
     r = command_parser.Resolver()
     actual = r.resolve_command_as_list('tail -f ~/file.txt | cat -ne')
     expected = [
         '/usr/bin/tail', '-f', f'{Path.home()}/file.txt', '|', '/bin/cat',
         '-ne'
     ]
     self.assertEqual(actual, expected)
Esempio n. 11
0
 def test_resolve_command_as_list(self):
     """
     Test that we properly resolve a command to a list
     """
     r = command_parser.Resolver()
     actual = r.resolve_command_as_list(
         'tail -f ~/file.txt | grep [^a-z](.*?)<')
     expected = [
         '/usr/bin/tail', '-f', '/Users/chris/file.txt', '|',
         '/usr/bin/grep', '[^a-z](.*?)<'
     ]
     self.assertEqual(actual, expected)
Esempio n. 12
0
 def test_can_resolve_fake_path(self):
     """
     Test that we correctly resolve a fake path
     """
     r = command_parser.Resolver()
     self.assertEqual(r.get('tail123'), 'tail123')
Esempio n. 13
0
 def test_can_resolve_real_path(self):
     """
     Test that we correctly resolve a real path
     """
     r = command_parser.Resolver()
     self.assertEqual(r.get('tail'), '/usr/bin/tail')
Esempio n. 14
0
 def test_can_get_user_home(self):
     """
     Test that we get the user's home folder properly
     """
     r = command_parser.Resolver()
     self.assertEqual(r.user_home, str(Path.home()))
Esempio n. 15
0
 def test_can_create_resolver(self):
     """
     Test that we can create a resolver instance
     """
     r = command_parser.Resolver()
     self.assertIsInstance(r, command_parser.Resolver)