mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-22 22:06:43 +00:00
fix: reset modified environment variables after test
CustomLanguageTest was modifying a few environment variables and not restoring them when complete. This led to problems for later tests that expected those variables to be at their default values.
This commit is contained in:
parent
22ab6506e0
commit
67fd1f496c
@ -256,40 +256,8 @@ class EscapeMarkdownTest(unittest.TestCase):
|
|||||||
self.assertEqual(issue.body[1], '\\<AnotherTag\\>')
|
self.assertEqual(issue.body[1], '\\<AnotherTag\\>')
|
||||||
|
|
||||||
|
|
||||||
class CustomLanguageTest(unittest.TestCase):
|
class BaseCustomLanguageTests:
|
||||||
def test_custom_lang_load(self):
|
class BaseTest(unittest.TestCase):
|
||||||
os.environ['INPUT_LANGUAGES'] = 'tests/custom_languages.json'
|
|
||||||
parser = TodoParser()
|
|
||||||
# Test if the custom language ILS is actually loaded into the system
|
|
||||||
self.assertIsNotNone(parser.languages_dict['ILS'])
|
|
||||||
self.assertEqual(self.count_syntax(parser, 'ILS'), 1)
|
|
||||||
|
|
||||||
def test_custom_lang_not_dupplicate(self):
|
|
||||||
os.environ['INPUT_LANGUAGES'] = 'tests/custom_languages.json'
|
|
||||||
parser = TodoParser()
|
|
||||||
|
|
||||||
# Test if a custom language can overwrite the rules of an existing one
|
|
||||||
self.assertEqual(self.count_syntax(parser, 'Java'), 1)
|
|
||||||
for syntax in parser.syntax_dict:
|
|
||||||
if syntax['language'] == 'Java':
|
|
||||||
self.assertEqual(len(syntax['markers']), 2)
|
|
||||||
self.assertEqual(syntax['markers'][0]['pattern'], "////")
|
|
||||||
self.assertEqual(syntax['markers'][1]['pattern']['start'], '+=')
|
|
||||||
self.assertEqual(syntax['markers'][1]['pattern']['end'], '=+')
|
|
||||||
break
|
|
||||||
|
|
||||||
self.assertIsNotNone(parser.languages_dict['Java'])
|
|
||||||
self.assertEqual(len(parser.languages_dict['Java']['extensions']), 1)
|
|
||||||
self.assertEqual(parser.languages_dict['Java']['extensions'][0], ".java2")
|
|
||||||
|
|
||||||
def test_url_load(self):
|
|
||||||
os.environ['INPUT_LANGUAGES'] = 'https://raw.githubusercontent.com/alstr/todo-to-issue-action/master/tests/custom_languages.json'
|
|
||||||
os.environ['INPUT_NO_STANDARD'] = 'true'
|
|
||||||
parser = TodoParser()
|
|
||||||
|
|
||||||
self.assertEqual(len(parser.languages_dict), 2)
|
|
||||||
self.assertEqual(len(parser.syntax_dict), 2)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def count_syntax(parser: TodoParser, name: str):
|
def count_syntax(parser: TodoParser, name: str):
|
||||||
counter = 0
|
counter = 0
|
||||||
@ -299,3 +267,48 @@ class CustomLanguageTest(unittest.TestCase):
|
|||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
|
|
||||||
return counter
|
return counter
|
||||||
|
|
||||||
|
|
||||||
|
class CustomLanguageFileTest(BaseCustomLanguageTests.BaseTest):
|
||||||
|
def setUp(self):
|
||||||
|
os.environ['INPUT_LANGUAGES'] = 'tests/custom_languages.json'
|
||||||
|
self.parser = TodoParser()
|
||||||
|
|
||||||
|
def test_custom_lang_load(self):
|
||||||
|
# Test if the custom language ILS is actually loaded into the system
|
||||||
|
self.assertIsNotNone(self.parser.languages_dict['ILS'])
|
||||||
|
self.assertEqual(self.count_syntax(self.parser, 'ILS'), 1)
|
||||||
|
|
||||||
|
def test_custom_lang_not_dupplicate(self):
|
||||||
|
|
||||||
|
# Test if a custom language can overwrite the rules of an existing one
|
||||||
|
self.assertEqual(self.count_syntax(self.parser, 'Java'), 1)
|
||||||
|
for syntax in self.parser.syntax_dict:
|
||||||
|
if syntax['language'] == 'Java':
|
||||||
|
self.assertEqual(len(syntax['markers']), 2)
|
||||||
|
self.assertEqual(syntax['markers'][0]['pattern'], "////")
|
||||||
|
self.assertEqual(syntax['markers'][1]['pattern']['start'], '+=')
|
||||||
|
self.assertEqual(syntax['markers'][1]['pattern']['end'], '=+')
|
||||||
|
break
|
||||||
|
|
||||||
|
self.assertIsNotNone(self.parser.languages_dict['Java'])
|
||||||
|
self.assertEqual(len(self.parser.languages_dict['Java']['extensions']), 1)
|
||||||
|
self.assertEqual(self.parser.languages_dict['Java']['extensions'][0], ".java2")
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
del os.environ['INPUT_LANGUAGES']
|
||||||
|
|
||||||
|
|
||||||
|
class CustomLanguageUrlTest(BaseCustomLanguageTests.BaseTest):
|
||||||
|
def setUp(self):
|
||||||
|
os.environ['INPUT_LANGUAGES'] = 'https://raw.githubusercontent.com/alstr/todo-to-issue-action/master/tests/custom_languages.json'
|
||||||
|
os.environ['INPUT_NO_STANDARD'] = 'true'
|
||||||
|
self.parser = TodoParser()
|
||||||
|
|
||||||
|
def test_url_load(self):
|
||||||
|
self.assertEqual(len(self.parser.languages_dict), 2)
|
||||||
|
self.assertEqual(len(self.parser.syntax_dict), 2)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
del os.environ['INPUT_LANGUAGES']
|
||||||
|
del os.environ['INPUT_NO_STANDARD']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user