Skip to content

Commit

Permalink
Merge pull request #343 from smartdevicelink/bugfix/generator_tests
Browse files Browse the repository at this point in the history
Fix failing RPC generator unit tests
  • Loading branch information
renonick87 authored Nov 12, 2020
2 parents a507078 + f99340c commit 3f035dc
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 25 deletions.
6 changes: 3 additions & 3 deletions generator/templates/base_struct_function.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base_template.js' %}

{% block typedef %}
{%- if description is defined or deprecated is defined %}
{%- if description is defined or deprecated is defined and deprecated is not none %}
/**
{% if description is defined -%}
{% for d in description -%}
Expand All @@ -10,7 +10,7 @@
{% else -%}
* Struct description not available.
{% endif -%}
{% if deprecated is defined -%}
{% if deprecated is defined and deprecated is not none -%}
* @deprecated
{% endif -%}
*/
Expand Down Expand Up @@ -76,7 +76,7 @@

/**
* Get the {{method.method_title}}
{% if deprecated is defined -%}
{% if deprecated is defined and deprecated is not none -%}
* @deprecated
{% endif -%}
* @returns {{'%s%s%s'|format('{', method.type, '}')}} - the {{method.key}} value
Expand Down
3 changes: 2 additions & 1 deletion generator/test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def main():
suite.addTests(TestLoader().loadTestsFromTestCase(CodeFormatAndQuality))

runner = TextTestRunner(verbosity=2)
runner.run(suite)
ret = not runner.run(suite).wasSuccessful()
sys.exit(ret)


if __name__ == '__main__':
Expand Down
14 changes: 10 additions & 4 deletions generator/test/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ def test_FunctionID(self):
expected['name'] = 'FunctionID'
expected['imports'] = {self.producer.imports(what='Enum', wherefrom='../../util/Enum.js')}
expected['methods'] = (self.producer.methods(method_title='RESERVED',
description=[], type='Number'),
description=[], type='Number', since=None, history=None, deprecated=None),
self.producer.methods(method_title='RegisterAppInterface',
description=[], type='Number'),
description=[], type='Number', since=None, history=None, deprecated=None),
self.producer.methods(method_title='PerformAudioPassThru',
description=[], type='Number'))
description=[], type='Number', since=None, history=None, deprecated=None))
expected['params'] = (self.producer.params(key='RESERVED', value="'RESERVED'"),
self.producer.params(key='RegisterAppInterface', value='0x01'),
self.producer.params(key='PerformAudioPassThru', value='0x10'))
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['extend'] = 'Enum'
result = self.producer.transform(item)
self.assertDictEqual(expected, result)
Expand All @@ -49,8 +52,11 @@ def test_Result(self):
expected['file_name'] = 'Result'
expected['imports'] = {self.producer.imports(what='Enum', wherefrom='../../util/Enum.js')}
expected['methods'] = (self.producer.methods(method_title='SUCCESS',
description=[], type='String'),)
description=[], type='String', since=None, history=None, deprecated=None),)
expected['params'] = (self.producer.params(key='SUCCESS', value="'SUCCESS'"),)
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['extend'] = 'Enum'
result = self.producer.transform(item)
self.assertDictEqual(expected, result)
36 changes: 27 additions & 9 deletions generator/test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,25 @@ def test_RegisterAppInterfaceRequest(self):
expected['methods'] = (self.producer.methods(key='KEY_SDL_MSG_VERSION',
method_title='SdlMsgVersion', external='SdlMsgVersion',
description=['See SyncMsgVersion'], param_name='version',
type='SdlMsgVersion'),
type='SdlMsgVersion', param_values={}, since=None, history=None, deprecated=None),
self.producer.methods(key='KEY_FULL_APP_ID', method_title='FullAppID',
external=None, description=['ID used'], param_name='id',
type='String'),
type='String', param_values={}, since=None, history=None, deprecated=None),
self.producer.methods(key='KEY_DAY_COLOR_SCHEME', param_name='scheme',
method_title='DayColorScheme', external='TemplateColorScheme',
description=['A color scheme for all display layout templates.'],
type='TemplateColorScheme'),
type='TemplateColorScheme', param_values={}, since=None, history=None, deprecated=None),
self.producer.methods(key='KEY_TTS_NAME', param_name='name',
method_title='TtsName', external='TTSChunk',
description=['TTS string for'], type='TTSChunk[]'))
description=['TTS string for'], type='TTSChunk[]', param_values={}, since=None, history=None, deprecated=None))
expected['params'] = (self.producer.params(key='KEY_SDL_MSG_VERSION', value="'syncMsgVersion'"),
self.producer.params(key='KEY_FULL_APP_ID', value="'fullAppID'"),
self.producer.params(key='KEY_DAY_COLOR_SCHEME', value="'dayColorScheme'"),
self.producer.params(key='KEY_TTS_NAME', value="'ttsName'"),
self.producer.params(key='APP_ID_MAX_LENGTH', value=10))
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['func'] = 'RegisterAppInterface'
expected['extend'] = 'RpcRequest'

Expand Down Expand Up @@ -128,14 +131,17 @@ def test_RegisterAppInterfaceResponse(self):
expected['methods'] = (self.producer.methods(key='KEY_LANGUAGE',
method_title='Language', external='Language',
description=['The currently'], param_name='language',
type='Language'),
type='Language', param_values={}, since=None, history=None, deprecated=None),
self.producer.methods(key='KEY_SUPPORTED_DIAG_MODES',
method_title='SupportedDiagModes', external=None,
description=['Specifies the'], param_name='modes',
type='Number[]'))
type='Number[]', param_values={}, since=None, history=None, deprecated=None))
expected['params'] = (self.producer.params(key='KEY_LANGUAGE', value="'language'"),
self.producer.params(key='KEY_SUPPORTED_DIAG_MODES', value="'supportedDiagModes'"))
expected['description'] = ['The response']
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['func'] = 'RegisterAppInterface'
expected['extend'] = 'RpcResponse'
result = self.producer.transform(item)
Expand All @@ -151,6 +157,9 @@ def test_UnregisterAppInterfaceRequest(self):
self.producer.imports(what='FunctionID', wherefrom='../enums/FunctionID.js')}
expected['methods'] = ()
expected['params'] = ()
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['func'] = 'UnregisterAppInterface'
expected['extend'] = 'RpcRequest'
result = self.producer.transform(item)
Expand All @@ -173,9 +182,12 @@ def test_PutFileRequest(self):
expected['methods'] = (self.producer.methods(key='KEY_FILE_TYPE',
method_title='FileType', external='FileType',
description=['Selected file type.'], param_name='type',
type='FileType'),)
type='FileType', param_values={}, since=None, history=None, deprecated=None),)
expected['params'] = (self.producer.params(key='KEY_FILE_TYPE', value="'fileType'"),)
expected['description'] = ['Used to']
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['script'] = self.producer.get_file_content('templates/scripts/PutFileRequest.js')
expected['func'] = 'PutFile'
expected['extend'] = 'RpcRequest'
Expand All @@ -196,9 +208,12 @@ def test_OnEncodedSyncPDataNotification(self):
expected['methods'] = (self.producer.methods(key='KEY_URL',
method_title='URL', external=None,
description=['If'], param_name='url',
type='String'),)
type='String', param_values={}, since=None, history=None, deprecated=None),)
expected['params'] = (self.producer.params(key='KEY_URL', value="'URL'"),)
expected['description'] = ['Callback including']
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['func'] = 'OnEncodedSyncPData'
expected['extend'] = 'RpcNotification'
result = self.producer.transform(item)
Expand All @@ -220,9 +235,12 @@ def test_CreateInteractionChoiceSetRequest(self):
expected['methods'] = (self.producer.methods(key='KEY_CHOICE_SET',
method_title='ChoiceSet', external='Choice',
description=['A choice is an option given to'], param_name='set',
type='Choice[]'),)
type='Choice[]', param_values={}, since=None, history=None, deprecated=None),)
expected['params'] = (self.producer.params(key='KEY_CHOICE_SET', value="'choiceSet'"),)
expected['description'] = ['creates interaction']
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['func'] = 'CreateInteractionChoiceSet'
expected['extend'] = 'RpcRequest'
result = self.producer.transform(item)
Expand Down
7 changes: 5 additions & 2 deletions generator/test/test_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ def test_SoftButton(self):
expected['methods'] = (
self.producer.methods(
description=['Optional image'], external='Image', key='KEY_IMAGE', method_title='Image',
param_name='image', type='Image'),
param_name='image', type='Image', param_values={}, deprecated=None, history=None, since=None),
self.producer.methods(
description=[], external=None, key='KEY_VALUE', method_title='ValueParam',
param_name='value', type='String'))
param_name='value', type='String', param_values={}, deprecated=None, history=None, since=None))
expected['params'] = (self.producer.params(key='KEY_IMAGE', value="'image'"),
self.producer.params(key='KEY_VALUE', value="'value'"))
expected['since'] = None
expected['history'] = None
expected['deprecated'] = None
expected['extend'] = 'RpcStruct'
result = self.producer.transform(item)
self.assertDictEqual(expected, result)
9 changes: 3 additions & 6 deletions generator/transformers/common_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ def transform(self, item) -> dict:

if getattr(item, 'description', None):
render['description'] = self.extract_description(item.description)
if item.deprecated:
render['deprecated'] = item.deprecated
if item.history:
render['history'] = item.history
if item.since:
render['since'] = item.since
render['since'] = item.since
render['history'] = item.history
render['deprecated'] = item.deprecated

self.custom_mapping(render, item)

Expand Down

0 comments on commit 3f035dc

Please sign in to comment.