Skip to content

Commit

Permalink
Make sure our paths in fixtures contain utf8
Browse files Browse the repository at this point in the history
in order to have confidence in our ability to handle utf8 path location
we just add random utf8 string named sub-dirs to our path fixtures.

Closes: #106
  • Loading branch information
elbenfreund committed Apr 25, 2016
1 parent c4c9885 commit 71d55c0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,25 @@ def filepath(tmpdir, filename):

@pytest.fixture
def appdirs(mocker, tmpdir):
"""Provide mocked version specific user dirs using a tmpdir."""
"""
Provide mocked version specific user dirs using a tmpdir.
We add a utf8-subdir to our paths to make sure our consuming methods can cope with it.
"""
def ensure_directory_exists(directory):
if not os.path.lexists(directory):
os.makedirs(directory)
return directory

hamster_cli.AppDirs = mocker.MagicMock()
hamster_cli.AppDirs.user_config_dir = ensure_directory_exists(os.path.join(
tmpdir.mkdir('config').strpath, 'hamster_cli/'))
tmpdir.mkdir('config').mkdir(fauxfactory.gen_utf8()).strpath, 'hamster_cli/'))
hamster_cli.AppDirs.user_data_dir = ensure_directory_exists(os.path.join(
tmpdir.mkdir('data').strpath, 'hamster_cli/'))
tmpdir.mkdir('data').mkdir(fauxfactory.gen_utf8()).strpath, 'hamster_cli/'))
hamster_cli.AppDirs.user_cache_dir = ensure_directory_exists(os.path.join(
tmpdir.mkdir('cache').strpath, 'hamster_cli/'))
tmpdir.mkdir('cache').mkdir(fauxfactory.gen_utf8()).strpath, 'hamster_cli/'))
hamster_cli.AppDirs.user_log_dir = ensure_directory_exists(os.path.join(
tmpdir.mkdir('log').strpath, 'hamster_cli/'))
tmpdir.mkdir('log').mkdir(fauxfactory.gen_utf8()).strpath, 'hamster_cli/'))
return hamster_cli.AppDirs


Expand Down Expand Up @@ -92,7 +96,7 @@ def lib_config(tmpdir):
'day_start': datetime.time(hour=0, minute=0, second=0),
'db_engine': 'sqlite',
'db_path': ':memory:',
'tmpfile_path': os.path.join(tmpdir.mkdir('cache2').strpath, 'test.pickle'),
'tmpfile_path': os.path.join(tmpdir.mkdir(fauxfactory.gen_utf8()).strpath, 'test.pickle'),
'fact_min_delta': 60,
}

Expand All @@ -110,8 +114,8 @@ def client_config(tmpdir):
'log_level': 10,
'log_console': False,
'logfile_path': False,
'export_path': os.path.join(tmpdir.mkdir('export').strpath, 'export'),
'logging_path': os.path.join(tmpdir.mkdir('log2').strpath, 'hamster_cli.log'),
'export_path': os.path.join(tmpdir.mkdir('export').mkdir(fauxfactory.gen_utf8()).strpath, 'export'),
'logging_path': os.path.join(tmpdir.mkdir('log2').mkdir(fauxfactory.gen_utf8()).strpath, 'hamster_cli.log'),
}


Expand All @@ -127,7 +131,7 @@ def generate_config(**kwargs):
config.set('Backend', 'fact_min_delta', kwargs.get('fact_min_delta', '60'))
config.set('Backend', 'db_engine', kwargs.get('db_engine', 'sqlite'))
config.set('Backend', 'db_path', kwargs.get('db_path', os.path.join(
tmpdir.strpath, 'hamster_db.sqlite')))
tmpdir.mkdir(fauxfactory.gen_utf8()).strpath, 'hamster_db.sqlite')))
config.set('Backend', 'db_host', kwargs.get('db_host', ''))
config.set('Backend', 'db_name', kwargs.get('db_name', ''))
config.set('Backend', 'db_port', kwargs.get('db_port', ''))
Expand Down

0 comments on commit 71d55c0

Please sign in to comment.