Integrating up through commit 90f050496
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch, mock_open
|
||||
|
||||
from commit_validation.tests.mocks.mock_commit import MockCommit
|
||||
from commit_validation.validators.unicode_validator import UnicodeValidator
|
||||
|
||||
|
||||
class UnicodeValidatorTests(unittest.TestCase):
|
||||
|
||||
@patch('builtins.open', mock_open(read_data='This file contains no unicode characters'))
|
||||
def test_fileWithNoUnicode_passes(self):
|
||||
commit = MockCommit(files=['/someCppFile.cpp'])
|
||||
error_list = []
|
||||
self.assertTrue(UnicodeValidator().run(commit, error_list))
|
||||
self.assertEqual(len(error_list), 0, f"Unexpected errors: {error_list}")
|
||||
|
||||
@patch('builtins.open', mock_open(read_data='This file contains unicode character \u2318'))
|
||||
def test_fileWithUnicode_fails(self):
|
||||
commit = MockCommit(files=['/someCppFile.cpp'])
|
||||
error_list = []
|
||||
self.assertFalse(UnicodeValidator().run(commit, error_list))
|
||||
self.assertNotEqual(len(error_list), 0, f"Errors were expected but none were returned.")
|
||||
|
||||
@patch('builtins.open', mock_open(read_data='This file contains unicode character \u2318'))
|
||||
def test_fileExtensionIgnored_passes(self):
|
||||
commit = MockCommit(files=['/someCppFile.somerandomextension'])
|
||||
error_list = []
|
||||
self.assertTrue(UnicodeValidator().run(commit, error_list))
|
||||
self.assertEqual(len(error_list), 0, f"Unexpected errors: {error_list}")
|
||||
|
||||
@patch('builtins.open', mock_open(read_data='This file contains unicode character: \\u2318'))
|
||||
def test_fileWithEscapedUnicode_passes(self):
|
||||
commit = MockCommit(files=['/someCppFile.cpp'])
|
||||
error_list = []
|
||||
self.assertTrue(UnicodeValidator().run(commit, error_list))
|
||||
self.assertEqual(len(error_list), 0, f"Unexpected errors: {error_list}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user