diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py
index 872be033..fab70e9b 100644
--- a/tests/lib/__init__.py
+++ b/tests/lib/__init__.py
@@ -24,7 +24,7 @@ def urllib_read(query_url):
elif query_url.startswith('http://freegeoip.net/json/'):
return '{"city": "Meppen", "region_code": "06", "region_name": "Niedersachsen", "areacode": "", "ip": "82.145.55.16", "zipcode": "49716", "longitude": 7.3167, "country_name": "Germany", "country_code": "DE", "metrocode": "", "latitude": 52.6833}'
elif query_url.startswith('http://query.yahooapis.com/v1/public/'):
- return '{"query":{"count":1,"created":"2013-03-02T13:20:22Z","lang":"en-US","results":{"weather":{"rss":{"version":"2.0","geo":"http://www.w3.org/2003/01/geo/wgs84_pos#","yweather":"http://xml.weather.yahoo.com/ns/rss/1.0","channel":{"title":"Yahoo! Weather - Russia, RU","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Russia__RU/*http://weather.yahoo.com/forecast/RSXX1511_c.html","description":"Yahoo! Weather for Russia, RU","language":"en-us","lastBuildDate":"Sat, 02 Mar 2013 4:58 pm MSK","ttl":"60","location":{"city":"Russia","country":"Russia","region":""},"units":{"distance":"km","pressure":"mb","speed":"km/h","temperature":"C"},"wind":{"chill":"-11","direction":"0","speed":""},"atmosphere":{"humidity":"94","pressure":"1006.1","rising":"0","visibility":""},"astronomy":{"sunrise":"10:04 am","sunset":"7:57 pm"},"image":{"title":"Yahoo! Weather","width":"142","height":"18","link":"http://weather.yahoo.com","url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"},"item":{"title":"Conditions for Russia, RU at 4:58 pm MSK","lat":"59.45","long":"108.83","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Russia__RU/*http://weather.yahoo.com/forecast/RSXX1511_c.html","pubDate":"Sat, 02 Mar 2013 4:58 pm MSK","condition":{"code":"30","date":"Sat, 02 Mar 2013 4:58 pm MSK","temp":"-11","text":"Partly Cloudy"},"description":"
\nCurrent Conditions:
\nPartly Cloudy, -11 C
\n
Forecast:
\nSat - Partly Cloudy. High: -9 Low: -19
\nSun - Partly Cloudy. High: -12 Low: -18
\n
\nFull Forecast at Yahoo! Weather
\n(provided by The Weather Channel)
","forecast":[{"code":"29","date":"2 Mar 2013","day":"Sat","high":"-9","low":"-19","text":"Partly Cloudy"},{"code":"30","date":"3 Mar 2013","day":"Sun","high":"-12","low":"-18","text":"Partly Cloudy"}],"guid":{"isPermaLink":"false","content":"RSXX1511_2013_03_03_7_00_MSK"}}}}}}}}'
+ return r'{"query":{"count":1,"created":"2013-03-02T13:20:22Z","lang":"en-US","results":{"weather":{"rss":{"version":"2.0","geo":"http://www.w3.org/2003/01/geo/wgs84_pos#","yweather":"http://xml.weather.yahoo.com/ns/rss/1.0","channel":{"title":"Yahoo! Weather - Russia, RU","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Russia__RU/*http://weather.yahoo.com/forecast/RSXX1511_c.html","description":"Yahoo! Weather for Russia, RU","language":"en-us","lastBuildDate":"Sat, 02 Mar 2013 4:58 pm MSK","ttl":"60","location":{"city":"Russia","country":"Russia","region":""},"units":{"distance":"km","pressure":"mb","speed":"km/h","temperature":"C"},"wind":{"chill":"-11","direction":"0","speed":""},"atmosphere":{"humidity":"94","pressure":"1006.1","rising":"0","visibility":""},"astronomy":{"sunrise":"10:04 am","sunset":"7:57 pm"},"image":{"title":"Yahoo! Weather","width":"142","height":"18","link":"http://weather.yahoo.com","url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"},"item":{"title":"Conditions for Russia, RU at 4:58 pm MSK","lat":"59.45","long":"108.83","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Russia__RU/*http://weather.yahoo.com/forecast/RSXX1511_c.html","pubDate":"Sat, 02 Mar 2013 4:58 pm MSK","condition":{"code":"30","date":"Sat, 02 Mar 2013 4:58 pm MSK","temp":"-11","text":"Partly Cloudy"},"description":"
\nCurrent Conditions:
\nPartly Cloudy, -11 C
\n
Forecast:
\nSat - Partly Cloudy. High: -9 Low: -19
\nSun - Partly Cloudy. High: -12 Low: -18
\n
\nFull Forecast at Yahoo! Weather
\n(provided by The Weather Channel)
","forecast":[{"code":"29","date":"2 Mar 2013","day":"Sat","high":"-9","low":"-19","text":"Partly Cloudy"},{"code":"30","date":"3 Mar 2013","day":"Sun","high":"-12","low":"-18","text":"Partly Cloudy"}],"guid":{"isPermaLink":"false","content":"RSXX1511_2013_03_03_7_00_MSK"}}}}}}}}'
else:
raise NotImplementedError
diff --git a/tests/test_segments.py b/tests/test_segments.py
index 8b407b78..6eedcbae 100644
--- a/tests/test_segments.py
+++ b/tests/test_segments.py
@@ -130,12 +130,41 @@ class TestCommon(TestCase):
self.assertEqual(common.external_ip(), [{'contents': '127.0.0.1', 'divider_highlight_group': 'background:divider'}])
def test_uptime(self):
- # TODO
- pass
+ with replace_module_attr(common, '_get_uptime', lambda: 65536):
+ self.assertEqual(common.uptime(), [{'contents': '0d 18h 12m', 'divider_highlight_group': 'background:divider'}])
+
+ def _get_uptime():
+ raise NotImplementedError
+
+ with replace_module_attr(common, '_get_uptime', _get_uptime):
+ self.assertEqual(common.uptime(), None)
def test_weather(self):
- # TODO
- pass
+ with replace_module_attr(common, 'urllib_read', urllib_read):
+ self.assertEqual(common.weather(), [
+ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
+ {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_cold', 'weather_temp', 'weather'], 'contents': '-11°C'}
+ ])
+ self.assertEqual(common.weather(icons={'cloudy': 'o'}), [
+ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': 'o '},
+ {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_cold', 'weather_temp', 'weather'], 'contents': '-11°C'}
+ ])
+ self.assertEqual(common.weather(icons={'partly_cloudy_day': 'x'}), [
+ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': 'x '},
+ {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_cold', 'weather_temp', 'weather'], 'contents': '-11°C'}
+ ])
+ self.assertEqual(common.weather(unit='F'), [
+ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
+ {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_cold', 'weather_temp', 'weather'], 'contents': '12°F'}
+ ])
+ self.assertEqual(common.weather(unit='K'), [
+ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
+ {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_cold', 'weather_temp', 'weather'], 'contents': '262K'}
+ ])
+ self.assertEqual(common.weather(temperature_format='{temp:.1e}C'), [
+ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
+ {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_cold', 'weather_temp', 'weather'], 'contents': '-1.1e+01C'}
+ ])
def test_system_load(self):
with replace_module_module(common, 'os', getloadavg=lambda: (7.5, 3.5, 1.5)):
@@ -154,8 +183,35 @@ class TestCommon(TestCase):
self.assertEqual(common.cpu_load_percent(), '52%')
def test_network_load(self):
- # TODO
- pass
+ def _get_bytes(interface):
+ return None
+ with replace_module_attr(common, '_get_bytes', _get_bytes):
+ self.assertEqual(common.network_load(), None)
+ l = [0, 0]
+
+ def _get_bytes2(interface):
+ l[0] += 1200
+ l[1] += 2400
+ return tuple(l)
+
+ from imp import reload
+ reload(common)
+ with replace_module_attr(common, '_get_bytes', _get_bytes2):
+ common.network_load.startup()
+ common.network_load.sleep(0)
+ common.network_load.sleep(0)
+ self.assertEqual(common.network_load(), [
+ {'divider_highlight_group': 'background:divider', 'contents': '⬇ 1 KiB/s ⬆ 2 KiB/s'}
+ ])
+ self.assertEqual(common.network_load(format='r {recv} s {sent}'), [
+ {'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s s 2 KiB/s'}
+ ])
+ self.assertEqual(common.network_load(format='r {recv} s {sent}', suffix='bps'), [
+ {'divider_highlight_group': 'background:divider', 'contents': 'r 1 Kibps s 2 Kibps'}
+ ])
+ self.assertEqual(common.network_load(format='r {recv} s {sent}', si_prefix=True), [
+ {'divider_highlight_group': 'background:divider', 'contents': 'r 1 kB/s s 2 kB/s'}
+ ])
def test_virtualenv(self):
with replace_env('VIRTUAL_ENV', '/abc/def/ghi'):
@@ -269,16 +325,36 @@ class TestVim(TestCase):
self.assertEqual(vim.modified_buffers(), None)
def test_branch(self):
- # TODO
- pass
+ with vim_module._with('buffer', '/foo') as segment_info:
+ with replace_module_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: None, directory=path)):
+ self.assertEqual(vim.branch(segment_info=segment_info),
+ [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}])
+ self.assertEqual(vim.branch(segment_info=segment_info, status_colors=True),
+ [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}])
+ with replace_module_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: 'DU', directory=path)):
+ self.assertEqual(vim.branch(segment_info=segment_info),
+ [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}])
+ self.assertEqual(vim.branch(segment_info=segment_info, status_colors=True),
+ [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}])
def test_file_vcs_status(self):
- # TODO
- pass
+ with vim_module._with('buffer', '/foo') as segment_info:
+ with replace_module_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: 'M', directory=path)):
+ self.assertEqual(vim.file_vcs_status(segment_info=segment_info),
+ [{'highlight_group': ['file_vcs_status_M', 'file_vcs_status'], 'contents': 'M'}])
+ with replace_module_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: None, directory=path)):
+ self.assertEqual(vim.file_vcs_status(segment_info=segment_info), None)
+ with vim_module._with('buffer', '/bar') as segment_info:
+ with vim_module._with('bufoptions', buftype='nofile'):
+ with replace_module_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: 'M', directory=path)):
+ self.assertEqual(vim.file_vcs_status(segment_info=segment_info), None)
def test_repository_status(self):
- # TODO
- pass
+ segment_info = vim_module._get_segment_info()
+ with replace_module_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: None, directory=path)):
+ self.assertEqual(vim.repository_status(segment_info=segment_info), None)
+ with replace_module_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: 'DU', directory=path)):
+ self.assertEqual(vim.repository_status(segment_info=segment_info), 'DU')
old_cwd = None