import logging
import os
import unittest
import validate_token
class ValidateTokenTests(unittest.TestCase):
def test_valid_tokens(self):
with self.assertLogs() as logs:
logging.info('ensure non-empty log')
has_token_error = validate_token.ValidateTokenInFile(
f'{os.path.dirname(__file__)}/test_data/histograms.xml')
self.assertFalse(has_token_error)
self.assertEqual(len(logs.output), 1)
def test_invalid_tokens(self):
with self.assertLogs() as logs:
has_token_error = validate_token.ValidateTokenInFile(
f'{os.path.dirname(__file__)}'
'/test_data/tokens/token_errors_histograms.xml')
self.assertTrue(has_token_error)
self.assertEqual(len(logs.output), 1)
output = logs.output[0]
self.assertIn('Token(s) TestToken3 in', output)
self.assertIn('Test.{TestToken3}.Histogram.{TestToken}.{TestToken2}',
output)
if __name__ == '__main__':
unittest.main()