Just a few things

This commit is contained in:
Huluti 2017-02-04 11:00:52 +01:00
parent d3d4380466
commit 6e7b4c506f
4 changed files with 12 additions and 26 deletions

View File

@ -13,6 +13,8 @@ from gi.repository import Gtk, GdkPixbuf
class ManjaroHello():
"""Manjaro-Hello"""
def __init__(self):
# App vars
self.app = "manjaro-hello"
@ -202,16 +204,16 @@ class ManjaroHello():
f.write(content.replace(i3_autostart, "#" + i3_autostart))
f.truncate()
self.autostart = autostart
except OSError as e:
print(e)
except OSError as error:
print(error)
def save_preferences(self):
"""Save preferences in config file."""
try:
with open(self.preferences_path, "w") as f:
json.dump(self.preferences, f)
except OSError as e:
print(e)
except OSError as error:
print(error)
def get_preferences(self):
"""Read preferences from config file."""
@ -300,12 +302,16 @@ def get_lsb_infos():
arg = arg[1:-1]
if arg:
lsb[var] = arg
except OSError as e:
print(e)
except OSError as error:
print(error)
return lsb
def read_json(path):
"""Read content of a json file.
:return: json content
:rtype: str
"""
try:
with open(path, "r") as f:
return json.load(f)

View File

View File

@ -1,3 +0,0 @@
{
"test": "json"
}

View File

@ -1,17 +0,0 @@
import unittest
from src import manjaro_hello
class ManjaroHello(unittest.TestCase):
def setUp(self):
self.path = "test/"
def test_read_json(self):
json = manjaro_hello.read_json(self.path + "test.json")
self.assertEqual(json, {"test": "json"})
json = manjaro_hello.read_json(self.path + "test")
self.assertEqual(json, None)
def test_get_lsb_infos(self):
self.assertIsInstance(manjaro_hello.get_lsb_infos(), dict)