debug_info_request_test.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 copy import deepcopy
  18. from hamcrest import assert_that, contains_string, equal_to
  19. from unittest import TestCase
  20. from ycm.client.debug_info_request import FormatDebugInfoResponse
  21. GENERIC_RESPONSE = {
  22. 'clang': {
  23. 'has_support': True,
  24. 'version': 'Clang version'
  25. },
  26. 'completer': {
  27. 'items': [
  28. {
  29. 'key': 'key',
  30. 'value': 'value'
  31. }
  32. ],
  33. 'name': 'Completer name',
  34. 'servers': [
  35. {
  36. 'address': '127.0.0.1',
  37. 'executable': '/path/to/executable',
  38. 'extras': [
  39. {
  40. 'key': 'key',
  41. 'value': 'value'
  42. }
  43. ],
  44. 'is_running': True,
  45. 'logfiles': [
  46. '/path/to/stdout/logfile',
  47. '/path/to/stderr/logfile'
  48. ],
  49. 'name': 'Server name',
  50. 'pid': 12345,
  51. 'port': 1234
  52. }
  53. ]
  54. },
  55. 'extra_conf': {
  56. 'is_loaded': False,
  57. 'path': '/path/to/extra/conf'
  58. },
  59. 'python': {
  60. 'executable': '/path/to/python/interpreter',
  61. 'version': 'Python version'
  62. }
  63. }
  64. class DebugInfoRequestTest( TestCase ):
  65. def test_FormatDebugInfoResponse_NoResponse( self ):
  66. assert_that(
  67. FormatDebugInfoResponse( None ),
  68. equal_to( 'Server errored, no debug info from server\n' )
  69. )
  70. def test_FormatDebugInfoResponse_NoExtraConf( self ):
  71. response = deepcopy( GENERIC_RESPONSE )
  72. response[ 'extra_conf' ].update( {
  73. 'is_loaded': False,
  74. 'path': None
  75. } )
  76. assert_that(
  77. FormatDebugInfoResponse( response ),
  78. contains_string(
  79. 'No extra configuration file found\n'
  80. )
  81. )
  82. def test_FormatDebugInfoResponse_ExtraConfFoundButNotLoaded( self ):
  83. response = deepcopy( GENERIC_RESPONSE )
  84. response[ 'extra_conf' ].update( {
  85. 'is_loaded': False,
  86. 'path': '/path/to/extra/conf'
  87. } )
  88. assert_that(
  89. FormatDebugInfoResponse( response ),
  90. contains_string(
  91. 'Extra configuration file found but not loaded\n'
  92. 'Extra configuration path: /path/to/extra/conf\n'
  93. )
  94. )
  95. def test_FormatDebugInfoResponse_ExtraConfFoundAndLoaded( self ):
  96. response = deepcopy( GENERIC_RESPONSE )
  97. response[ 'extra_conf' ].update( {
  98. 'is_loaded': True,
  99. 'path': '/path/to/extra/conf'
  100. } )
  101. assert_that(
  102. FormatDebugInfoResponse( response ),
  103. contains_string(
  104. 'Extra configuration file found and loaded\n'
  105. 'Extra configuration path: /path/to/extra/conf\n'
  106. )
  107. )
  108. def test_FormatDebugInfoResponse_Completer_ServerRunningWithHost( self ):
  109. response = deepcopy( GENERIC_RESPONSE )
  110. assert_that(
  111. FormatDebugInfoResponse( response ),
  112. contains_string(
  113. 'Completer name completer debug information:\n'
  114. ' Server name running at: http://127.0.0.1:1234\n'
  115. ' Server name process ID: 12345\n'
  116. ' Server name executable: /path/to/executable\n'
  117. ' Server name logfiles:\n'
  118. ' /path/to/stdout/logfile\n'
  119. ' /path/to/stderr/logfile\n'
  120. ' Server name key: value\n'
  121. ' Key: value\n'
  122. )
  123. )
  124. def test_FormatDebugInfoResponse_Completer_ServerRunningWithoutHost( self ):
  125. response = deepcopy( GENERIC_RESPONSE )
  126. response[ 'completer' ][ 'servers' ][ 0 ].update( {
  127. 'address': None,
  128. 'port': None
  129. } )
  130. assert_that(
  131. FormatDebugInfoResponse( response ),
  132. contains_string(
  133. 'Completer name completer debug information:\n'
  134. ' Server name running\n'
  135. ' Server name process ID: 12345\n'
  136. ' Server name executable: /path/to/executable\n'
  137. ' Server name logfiles:\n'
  138. ' /path/to/stdout/logfile\n'
  139. ' /path/to/stderr/logfile\n'
  140. ' Server name key: value\n'
  141. ' Key: value\n'
  142. )
  143. )
  144. def test_FormatDebugInfoResponse_Completer_ServerNotRunningWithNoLogfiles(
  145. self ):
  146. response = deepcopy( GENERIC_RESPONSE )
  147. response[ 'completer' ][ 'servers' ][ 0 ].update( {
  148. 'is_running': False,
  149. 'logfiles': []
  150. } )
  151. assert_that(
  152. FormatDebugInfoResponse( response ),
  153. contains_string(
  154. 'Completer name completer debug information:\n'
  155. ' Server name not running\n'
  156. ' Server name executable: /path/to/executable\n'
  157. ' No logfiles available\n'
  158. ' Server name key: value\n'
  159. ' Key: value\n'
  160. )
  161. )