def test_data(self): """Test data dir with XDG_DATA_HOME not set.""" with helpers.environ_set_temp('HOME', self.temp_dir): cur_dir = utils.get_standard_dir(QStandardPaths.DataLocation) self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.local', 'share', 'qutebrowser')) self.assertTrue(os.path.exists(cur_dir))
def test_cache(self): """Test cache dir with XDG_CACHE_HOME not set.""" with helpers.environ_set_temp('HOME', self.temp_dir): cur_dir = utils.get_standard_dir(QStandardPaths.CacheLocation) self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.cache', 'qutebrowser')) self.assertTrue(os.path.exists(cur_dir))
def test_config_explicit(self): """Test config dir with XDG_CONFIG_HOME explicitely set.""" with helpers.environ_set_temp('XDG_CONFIG_HOME', self.temp_dir): cur_dir = utils.get_standard_dir(QStandardPaths.ConfigLocation) self.assertEqual(cur_dir, os.path.join(self.temp_dir, 'qutebrowser')) self.assertTrue(os.path.exists(cur_dir))
def test_config_none(self): """Test initializing with config path set to None.""" args = types.SimpleNamespace(confdir='') with helpers.environ_set_temp(self.env): standarddir.init(args) config.init() self.assertFalse(os.listdir(self.conf_path))
def test_config(self): """Test config dir with XDG_CONFIG_HOME not set.""" with helpers.environ_set_temp('HOME', self.temp_dir): cur_dir = standarddir.get( QStandardPaths.ConfigLocation) self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.config', 'qutebrowser'))
def test_data(self): """Test data dir with XDG_DATA_HOME not set.""" with helpers.environ_set_temp('HOME', self.temp_dir): cur_dir = standarddir.get(QStandardPaths.DataLocation) self.assertEqual( cur_dir, os.path.join(self.temp_dir, '.local', 'share', 'qutebrowser'))
def test_cache(self): """Test cache dir with XDG_CACHE_HOME not set.""" env = {'HOME': self.temp_dir, 'XDG_CACHE_HOME': None} with helpers.environ_set_temp(env): standarddir.init(None) expected = os.path.join(self.temp_dir, '.cache', 'qutebrowser') self.assertEqual(standarddir.cache(), expected)
def test_data(self): """Test data dir with XDG_DATA_HOME not set.""" env = {'HOME': self.temp_dir, 'XDG_DATA_HOME': None} with helpers.environ_set_temp(env): standarddir.init(None) expected = os.path.join(self.temp_dir, '.local', 'share', 'qutebrowser') self.assertEqual(standarddir.data(), expected)
def test_environ_multiple(self): """Test environ_set_temp with multiple values.""" os.environ['QUTEBROWSER_ENVIRON_TEST_1'] = 'oldval_1' os.environ['QUTEBROWSER_ENVIRON_TEST_3'] = 'oldval_3' env = { 'QUTEBROWSER_ENVIRON_TEST_1': 'newval_1', 'QUTEBROWSER_ENVIRON_TEST_2': 'newval_2', 'QUTEBROWSER_ENVIRON_TEST_3': None, } with helpers.environ_set_temp(env): self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST_1'], 'newval_1') self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST_2'], 'newval_2') self.assertNotIn('QUTEBROWSER_ENVIRON_TEST_3', os.environ) self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST_1'], 'oldval_1') self.assertNotIn('QUTEBROWSER_ENVIRON_TEST_2', os.environ) self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST_3'], 'oldval_3')
def test_environ_unset(self): """Test environ_set_temp with something which wasn't set yet.""" with helpers.environ_set_temp('QUTEBROWSER_ENVIRON_TEST', 'newval'): self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST'], 'newval') self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ)
def test_environ_set(self): """Test environ_set_temp with something which was set already.""" os.environ['QUTEBROWSER_ENVIRON_TEST'] = 'oldval' with helpers.environ_set_temp('QUTEBROWSER_ENVIRON_TEST', 'newval'): self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST'], 'newval') self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST'], 'oldval')
def test_environ_none_unset(self): """Test environ_set_temp with something which wasn't set yet.""" with helpers.environ_set_temp({'QUTEBROWSER_ENVIRON_TEST': None}): self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ) self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ)
def test_cache_explicit(self): """Test cache dir with XDG_CACHE_HOME explicitely set.""" with helpers.environ_set_temp('XDG_CACHE_HOME', self.temp_dir): cur_dir = standarddir.get(QStandardPaths.CacheLocation) self.assertEqual(cur_dir, os.path.join(self.temp_dir, 'qutebrowser'))
def test_config(self): """Test config dir with XDG_CONFIG_HOME not set.""" with helpers.environ_set_temp('HOME', self.temp_dir): cur_dir = standarddir.get(QStandardPaths.ConfigLocation) self.assertEqual( cur_dir, os.path.join(self.temp_dir, '.config', 'qutebrowser'))
def test_data_explicit(self): """Test data dir with XDG_DATA_HOME explicitely set.""" with helpers.environ_set_temp('XDG_DATA_HOME', self.temp_dir): cur_dir = standarddir.get(QStandardPaths.DataLocation) self.assertEqual(cur_dir, os.path.join(self.temp_dir, 'qutebrowser'))
def test_cache(self): """Test cache dir with XDG_CACHE_HOME not set.""" with helpers.environ_set_temp('HOME', self.temp_dir): cur_dir = standarddir.get(QStandardPaths.CacheLocation) self.assertEqual( cur_dir, os.path.join(self.temp_dir, '.cache', 'qutebrowser'))
def test_data_explicit(self): """Test data dir with XDG_DATA_HOME explicitly set.""" with helpers.environ_set_temp({'XDG_DATA_HOME': self.temp_dir}): standarddir.init(None) expected = os.path.join(self.temp_dir, 'qutebrowser') self.assertEqual(standarddir.data(), expected)
def test_cache_explicit(self): """Test cache dir with XDG_CACHE_HOME explicitly set.""" with helpers.environ_set_temp({'XDG_CACHE_HOME': self.temp_dir}): standarddir.init(None) expected = os.path.join(self.temp_dir, 'qutebrowser') self.assertEqual(standarddir.cache(), expected)