debug_info_request_test.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # Copyright (C) 2017 YouCompleteMe Contributors
  2. #
  3. # This file is part of YouCompleteMe.
  4. #
  5. # YouCompleteMe is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # YouCompleteMe is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. from __future__ import unicode_literals
  18. from __future__ import print_function
  19. from __future__ import division
  20. from __future__ import absolute_import
  21. # Not installing aliases from python-future; it's unreliable and slow.
  22. from builtins import * # noqa
  23. from copy import deepcopy
  24. from hamcrest import assert_that, contains_string, equal_to
  25. from ycm.client.debug_info_request import FormatDebugInfoResponse
  26. GENERIC_RESPONSE = {
  27. 'clang': {
  28. 'has_support': True,
  29. 'version': 'Clang version'
  30. },
  31. 'completer': {
  32. 'items': [
  33. {
  34. 'key': 'key',
  35. 'value': 'value'
  36. }
  37. ],
  38. 'name': 'Completer name',
  39. 'servers': [
  40. {
  41. 'address': '127.0.0.1',
  42. 'executable': '/path/to/executable',
  43. 'extras': [
  44. {
  45. 'key': 'key',
  46. 'value': 'value'
  47. }
  48. ],
  49. 'is_running': True,
  50. 'logfiles': [
  51. '/path/to/stdout/logfile',
  52. '/path/to/stderr/logfile'
  53. ],
  54. 'name': 'Server name',
  55. 'pid': 12345,
  56. 'port': 1234
  57. }
  58. ]
  59. },
  60. 'extra_conf': {
  61. 'is_loaded': False,
  62. 'path': '/path/to/extra/conf'
  63. },
  64. 'python': {
  65. 'executable': '/path/to/python/interpreter',
  66. 'version': 'Python version'
  67. }
  68. }
  69. def FormatDebugInfoResponse_NoResponse_test():
  70. assert_that(
  71. FormatDebugInfoResponse( None ),
  72. equal_to( 'Server errored, no debug info from server\n' )
  73. )
  74. def FormatDebugInfoResponse_NoExtraConf_test():
  75. response = deepcopy( GENERIC_RESPONSE )
  76. response[ 'extra_conf' ].update( {
  77. 'is_loaded': False,
  78. 'path': None
  79. } )
  80. assert_that(
  81. FormatDebugInfoResponse( response ),
  82. contains_string(
  83. 'No extra configuration file found\n'
  84. )
  85. )
  86. def FormatDebugInfoResponse_ExtraConfFoundButNotLoaded_test():
  87. response = deepcopy( GENERIC_RESPONSE )
  88. response[ 'extra_conf' ].update( {
  89. 'is_loaded': False,
  90. 'path': '/path/to/extra/conf'
  91. } )
  92. assert_that(
  93. FormatDebugInfoResponse( response ),
  94. contains_string(
  95. 'Extra configuration file found but not loaded\n'
  96. 'Extra configuration path: /path/to/extra/conf\n'
  97. )
  98. )
  99. def FormatDebugInfoResponse_ExtraConfFoundAndLoaded_test():
  100. response = deepcopy( GENERIC_RESPONSE )
  101. response[ 'extra_conf' ].update( {
  102. 'is_loaded': True,
  103. 'path': '/path/to/extra/conf'
  104. } )
  105. assert_that(
  106. FormatDebugInfoResponse( response ),
  107. contains_string(
  108. 'Extra configuration file found and loaded\n'
  109. 'Extra configuration path: /path/to/extra/conf\n'
  110. )
  111. )
  112. def FormatDebugInfoResponse_Completer_ServerRunningWithHost_test():
  113. response = deepcopy( GENERIC_RESPONSE )
  114. assert_that(
  115. FormatDebugInfoResponse( response ),
  116. contains_string(
  117. 'Completer name completer debug information:\n'
  118. ' Server name running at: http://127.0.0.1:1234\n'
  119. ' Server name process ID: 12345\n'
  120. ' Server name executable: /path/to/executable\n'
  121. ' Server name logfiles:\n'
  122. ' /path/to/stdout/logfile\n'
  123. ' /path/to/stderr/logfile\n'
  124. ' Server name key: value\n'
  125. ' Key: value\n'
  126. )
  127. )
  128. def FormatDebugInfoResponse_Completer_ServerRunningWithoutHost_test():
  129. response = deepcopy( GENERIC_RESPONSE )
  130. response[ 'completer' ][ 'servers' ][ 0 ].update( {
  131. 'address': None,
  132. 'port': None
  133. } )
  134. assert_that(
  135. FormatDebugInfoResponse( response ),
  136. contains_string(
  137. 'Completer name completer debug information:\n'
  138. ' Server name running\n'
  139. ' Server name process ID: 12345\n'
  140. ' Server name executable: /path/to/executable\n'
  141. ' Server name logfiles:\n'
  142. ' /path/to/stdout/logfile\n'
  143. ' /path/to/stderr/logfile\n'
  144. ' Server name key: value\n'
  145. ' Key: value\n'
  146. )
  147. )
  148. def FormatDebugInfoResponse_Completer_ServerNotRunningWithNoLogfiles_test():
  149. response = deepcopy( GENERIC_RESPONSE )
  150. response[ 'completer' ][ 'servers' ][ 0 ].update( {
  151. 'is_running': False,
  152. 'logfiles': []
  153. } )
  154. assert_that(
  155. FormatDebugInfoResponse( response ),
  156. contains_string(
  157. 'Completer name completer debug information:\n'
  158. ' Server name not running\n'
  159. ' Server name executable: /path/to/executable\n'
  160. ' No logfiles available\n'
  161. ' Server name key: value\n'
  162. ' Key: value\n'
  163. )
  164. )