From 520f27d39db98b9b613edccb189f7f9452ba9e8e Mon Sep 17 00:00:00 2001 From: William Pietri Date: Mon, 4 Dec 2017 20:17:30 -0800 Subject: [PATCH] Does this work for Windows config file paths? --- sucks/cli.py | 6 +++++- tests/test_cli.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sucks/cli.py b/sucks/cli.py index 55b2831..4bc8240 100644 --- a/sucks/cli.py +++ b/sucks/cli.py @@ -1,6 +1,7 @@ import configparser import itertools import os +import platform import random import re @@ -39,7 +40,10 @@ FREQUENCY = FrequencyParamType() def config_file(): - return os.path.expanduser('~/.config/sucks.conf') + if platform.system() == 'Windows': + return os.path.join(os.getenv('APPDATA'), 'sucks.conf') + else: + return os.path.expanduser('~/.config/sucks.conf') def config_file_exists(): diff --git a/tests/test_cli.py b/tests/test_cli.py index 29cd02c..e4c9edd 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,6 +4,20 @@ from nose.tools import * from sucks.cli import * +def test_config_file_name(): + if platform.system() == 'Windows': + print(config_file()) + assert_true(re.match(r'[A-Z]:\\.+\\\w+\\AppData\\sucks.conf', config_file())) + else: + assert_true(re.match(r'/.+/\w+/.config/sucks.conf', config_file())) + + +# def test_write_and_read_config(): +# config1 = {'a':1, 'b':2} +# write_config(config1) +# config2 = read_config() +# assert_equals(config1, config2) + def test_frequency_param_type(): t = FREQUENCY assert_equals(t.convert('0', None, None), 0)