You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

  1. import os
  2. import sys
  3. import unittest
  4. import tempfile
  5. from ssh_config_utils.parser import CamelCase_to_snake
  6. samples_dir = os.path.join(sys.path[0], "sample_configs")
  7. CONFIG_FILES = dict(
  8. (file, os.path.join(samples_dir, file)) for file in os.listdir(samples_dir)
  9. )
  10. class ReadWriteTest(unittest.TestCase):
  11. def setUp(self):
  12. self.write_file = tempfile.TemporaryFile(mode="r+")
  13. def tearDown(self):
  14. self.write_file.close()
  15. class TestTempFile(ReadWriteTest):
  16. def test_me(self):
  17. self.write_file.write("hello")
  18. self.write_file.seek(0)
  19. self.assertEqual(self.write_file.read(), "hello")
  20. class TestParser(ReadWriteTest):
  21. def test_camel_case_to_snake_case(self):
  22. initial_vals = "ThisIsCamelCase", "This"
  23. expected_vals = "this_is_camel_case", "this"
  24. for initial, expected in zip(initial_vals, expected_vals):
  25. with self.subTest(initial=initial, expected=expected):
  26. self.assertEqual(CamelCase_to_snake(initial), expected)