# !/usr/bin/python
# -*- coding: utf-8 -*-
# testing private members is on purpose
# pylint: disable=protected-access
"""test class"""
import unittest
from plasoscaffolder.bll.mappings.mapping_helper import MappingHelper
from tests.test_helper import path_helper
[docs]class MappingHelperTest(unittest.TestCase):
""" Class representing a test case for the mapping helper functions. """
[docs] def setUp(self):
self.template_path = path_helper.TestTemplatePath()
yapf_path = path_helper.YapfStyleFilePath()
self.plugin_name = 'the_one_and_only'
self.file = 'test_template.jinja2'
self.helper = MappingHelper(self.template_path, yapf_path)
[docs] def testRender(self):
"""test the render """
context = {'plugin_name': self.plugin_name}
actual = self.helper.RenderTemplate(self.file, context)
expected = '# -*- coding: utf-8 -*-\n"""{0}"""\n'.format(
self.plugin_name)
self.assertEqual(expected, actual)
[docs] def testGenerateClassName(self):
"""Test the generation of the classname from the pluginname"""
name = 'this_is_a_test'
expected = 'ThisIsATest'
actual = self.helper.GenerateClassName(name)
self.assertEqual(expected, actual)
[docs] def testRemoveEscapeErrorWithSpacesLikeInTemplate(self):
"""Tests the removing of an escape error"""
string_with_error = 'u\'the first line\\\'\n u\'\\the second line'
string_without_error = 'u\'the first line\'\n u\'\\\\the second line'
actual = self.helper._RemoveEscapeError(string_with_error)
self.assertEqual(string_without_error, actual)
[docs] def testRemoveEscapeErrorWithNoEscape(self):
"""Tests the removing of an escape error"""
string_without_error = 'u\'the first line\\\\\'\n u\'the second line'
actual = self.helper._RemoveEscapeError(string_without_error)
self.assertEqual(string_without_error, actual)
[docs] def testRemoveBlanksAtEndOfLineForTwoBlanks(self):
"""Tests the removing of blanks at the end of a line"""
string_with_blank = 'somestuff \n'
string_without_blank = 'somestuff\n'
actual = self.helper._RemoveBlanksAtEndOfLine(string_with_blank)
self.assertEqual(string_without_blank, actual)
[docs] def testRemoveBlanksAtEndOfLineForFourBlanks(self):
"""Tests the removing of blanks at the end of a line"""
string_with_blank = ' \n'
string_without_blank = '\n'
actual = self.helper._RemoveBlanksAtEndOfLine(string_with_blank)
self.assertEqual(string_without_blank, actual)
[docs] def testRemoveBlanksAtEndOfLineFor12Blanks(self):
"""Tests the removing of blanks at the end of a line"""
string_with_blank = 'somestuff \n'
string_without_blank = 'somestuff\n'
actual = self.helper._RemoveBlanksAtEndOfLine(string_with_blank)
self.assertEqual(string_without_blank, actual)
if __name__ == '__main__':
unittest.main()