diff --git a/src/profile.py b/src/profile.py index d7a737b..1e52f60 100644 --- a/src/profile.py +++ b/src/profile.py @@ -10,14 +10,31 @@ class Profile(object): result = [] # check default path for fl in os.listdir(path): - if fl.endswith(".tox"): + if fl.endswith('.tox'): name = fl[:-4] result.append((path, name)) path = os.path.dirname(os.path.abspath(__file__)) # check current directory for fl in os.listdir(path): - if fl.endswith(".tox"): + if fl.endswith('.tox'): name = fl[:-4] result.append((path, name)) return result + @staticmethod + def open_profile(path, name): + Profile._path = path + name + '.tox' + with open(Profile._path, 'rb') as fl: + data = fl.read() + if data: + print 'Data loaded from: {}'.format(Profile._path) + return data + else: + raise IOError('Save file not found. Path: {}'.format(Profile._path)) + + @staticmethod + def save_profile(data): + with open(Profile._path, 'wb') as fl: + fl.write(data) + print 'Data saved to: {}'.format(Profile._path) + diff --git a/tests/tests.py b/tests/tests.py index 42a1f7f..76cb3b3 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -42,3 +42,13 @@ class TestProfile(): def test_search(self): arr = Profile.find_profiles() assert arr + + def test_open(self): + data = Profile.open_profile(Settings.get_default_path(), 'tox_save') + assert data + + def test_open_save(self): + data = Profile.open_profile(Settings.get_default_path(), 'tox_save') + Profile.save_profile(data) + new_data = Profile.open_profile(Settings.get_default_path(), 'tox_save') + assert new_data == data