Home | History | Annotate | Download | only in tests
      1 #!/usr/bin/env python3
      2 
      3 import os
      4 import tempfile
      5 import unittest
      6 
      7 from sourcedr.project import Config
      8 
      9 
     10 TESTDATA_DIR = os.path.join(os.path.dirname(__file__), 'testdata')
     11 
     12 
     13 class ConfigTest(unittest.TestCase):
     14     PROJECT_DIR = os.path.join(TESTDATA_DIR, 'project')
     15     CONFIG_PATH = os.path.join(PROJECT_DIR, Config.DEFAULT_NAME)
     16 
     17 
     18     def test_load(self):
     19         config = Config(self.CONFIG_PATH)
     20         config.load()
     21         self.assertEqual('path/to/android/src', config.source_dir)
     22 
     23 
     24     def test_save(self):
     25         with tempfile.TemporaryDirectory(prefix='test_sourcedr_') as tmp_dir:
     26             config_path = Config.get_default_path(tmp_dir)
     27             config = Config(config_path)
     28             config.source_dir = 'path/to/android/src'
     29             config.save()
     30             with open(config_path, 'r') as actual_fp:
     31                 actual = actual_fp.read().strip()
     32         with open(self.CONFIG_PATH, 'r') as expected_fp:
     33             expected = expected_fp.read().strip()
     34         self.assertEqual(actual, expected)
     35 
     36 
     37 if __name__ == '__main__':
     38     unittest.main()
     39