File: test_lib_config.py

package info (click to toggle)
powerline 2.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,884 kB
  • sloc: python: 23,040; sh: 1,783; ansic: 131; makefile: 70; csh: 51
file content (52 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)

import os

from powerline.lib.config import ConfigLoader

from tests.modules import TestCase
from tests.modules.lib.fsconfig import FSTree


FILE_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cfglib')


class LoadedList(list):
	def pop_all(self):
		try:
			return self[:]
		finally:
			self[:] = ()


loaded = LoadedList()


def on_load(key):
	loaded.append(key)


def check_file(path):
	if os.path.exists(path):
		return path
	else:
		raise IOError


class TestLoaderCondition(TestCase):
	def test_update_missing(self):
		loader = ConfigLoader(run_once=True)
		fpath = os.path.join(FILE_ROOT, 'file.json')
		self.assertRaises(IOError, loader.load, fpath)
		loader.register_missing(check_file, on_load, fpath)
		loader.update()  # This line must not raise IOError
		with FSTree({'file': {'test': 1}}, root=FILE_ROOT):
			loader.update()
			self.assertEqual(loader.load(fpath), {'test': 1})
			self.assertEqual(loaded.pop_all(), [fpath])


if __name__ == '__main__':
	from tests.modules import main
	main()