"Fossies" - the Fresh Open Source Software Archive

Member "http-prompt-2.1.0/tests/test_xdg.py" (5 Mar 2021, 2194 Bytes) of package /linux/www/http-prompt-2.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import os
    2 import stat
    3 import sys
    4 
    5 from .base import TempAppDirTestCase
    6 from http_prompt import xdg
    7 
    8 
    9 class TestXDG(TempAppDirTestCase):
   10 
   11     def test_get_app_data_home(self):
   12         path = xdg.get_data_dir()
   13         expected_path = os.path.join(os.environ[self.homes['data']],
   14                                      'http-prompt')
   15         self.assertEqual(path, expected_path)
   16         self.assertTrue(os.path.exists(path))
   17 
   18         if sys.platform != 'win32':
   19             # Make sure permission for the directory is 700
   20             mask = stat.S_IMODE(os.stat(path).st_mode)
   21             self.assertTrue(mask & stat.S_IRWXU)
   22             self.assertFalse(mask & stat.S_IRWXG)
   23             self.assertFalse(mask & stat.S_IRWXO)
   24 
   25     def test_get_app_config_home(self):
   26         path = xdg.get_config_dir()
   27         expected_path = os.path.join(os.environ[self.homes['config']],
   28                                      'http-prompt')
   29         self.assertEqual(path, expected_path)
   30         self.assertTrue(os.path.exists(path))
   31 
   32         if sys.platform != 'win32':
   33             # Make sure permission for the directory is 700
   34             mask = stat.S_IMODE(os.stat(path).st_mode)
   35             self.assertTrue(mask & stat.S_IRWXU)
   36             self.assertFalse(mask & stat.S_IRWXG)
   37             self.assertFalse(mask & stat.S_IRWXO)
   38 
   39     def test_get_resource_data_dir(self):
   40         path = xdg.get_data_dir('something')
   41         expected_path = os.path.join(
   42             os.environ[self.homes['data']], 'http-prompt', 'something')
   43         self.assertEqual(path, expected_path)
   44         self.assertTrue(os.path.exists(path))
   45 
   46         # Make sure we can write a file to the directory
   47         with open(os.path.join(path, 'test'), 'wb') as f:
   48             f.write(b'hello')
   49 
   50     def test_get_resource_config_dir(self):
   51         path = xdg.get_config_dir('something')
   52         expected_path = os.path.join(
   53             os.environ[self.homes['config']], 'http-prompt', 'something')
   54         self.assertEqual(path, expected_path)
   55         self.assertTrue(os.path.exists(path))
   56 
   57         # Make sure we can write a file to the directory
   58         with open(os.path.join(path, 'test'), 'wb') as f:
   59             f.write(b'hello')