Skip to content

Commit

Permalink
tests: replace 'tempdir' by 'tmp_path' fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Ott authored and fmarczin committed Dec 9, 2019
1 parent dcaa3c2 commit 6d1b31a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
12 changes: 5 additions & 7 deletions tests/basic_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import time
import tempfile
from tempdir import TempDir

import pytest
from simplekv._compat import BytesIO, xrange, text_type
Expand Down Expand Up @@ -133,14 +132,13 @@ def test_put_opened_file(self, store, key, value):

assert store.get(key) == value

def test_get_into_file(self, store, key, value):
with TempDir() as tmpdir:
store.put(key, value)
out_filename = os.path.join(tmpdir, 'output')
def test_get_into_file(self, store, key, value, tmp_path):
store.put(key, value)
out_filename = os.path.join(str(tmp_path), 'output')

store.get_file(key, out_filename)
store.get_file(key, out_filename)

assert open(out_filename, 'rb').read() == value
assert open(out_filename, 'rb').read() == value

def test_get_into_stream(self, store, key, value):
store.put(key, value)
Expand Down
17 changes: 7 additions & 10 deletions tests/test_boto_store.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os
from tempdir import TempDir

import pytest

Expand Down Expand Up @@ -48,18 +47,16 @@ def store(self, bucket, prefix, reduced_redundancy):
# Disable max key length test as it leads to problems with minio
test_max_key_length = None

def test_get_filename_nonexistant(self, store, key):
def test_get_filename_nonexistant(self, store, key, tmp_path):
# NOTE: boto misbehaves here and tries to erase the target file
# the parent tests use /dev/null, which you really should not try
# to os.remove!
with TempDir() as tmpdir:
with pytest.raises(KeyError):
store.get_file(key, os.path.join(tmpdir, 'a'))

def test_key_error_on_nonexistant_get_filename(self, store, key):
with TempDir() as tmpdir:
with pytest.raises(KeyError):
store.get_file(key, os.path.join(tmpdir, 'a'))
with pytest.raises(KeyError):
store.get_file(key, os.path.join(str(tmp_path), 'a'))

def test_key_error_on_nonexistant_get_filename(self, store, key, tmp_path):
with pytest.raises(KeyError):
store.get_file(key, os.path.join(str(tmp_path), 'a'))

def test_storage_class_put(
self, store, prefix, key, value, storage_class, bucket
Expand Down
6 changes: 2 additions & 4 deletions tests/test_filesystem_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from simplekv._compat import urlparse

from simplekv.fs import FilesystemStore, WebFilesystemStore
from tempdir import TempDir

from basic_store import BasicStore
from url_store import UrlStore
Expand All @@ -22,9 +21,8 @@

class TestBaseFilesystemStore(BasicStore, UrlStore, UUIDGen, HashGen):
@pytest.yield_fixture
def tmpdir(self):
with TempDir() as tmpdir:
yield tmpdir
def tmpdir(self, tmp_path):
yield str(tmp_path)

@pytest.fixture
def store(self, tmpdir):
Expand Down
8 changes: 3 additions & 5 deletions tests/test_git_store.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from basic_store import BasicStore
from dulwich.repo import Repo
from idgens import UUIDGen, HashGen
from tempdir import TempDir
import pytest

from simplekv.git import GitCommitStore
Expand All @@ -21,10 +20,9 @@ def subdir_name(self, request):
return request.param

@pytest.yield_fixture
def repo_path(self):
with TempDir() as tmpdir:
Repo.init_bare(tmpdir)
yield tmpdir
def repo_path(self, tmp_path):
Repo.init_bare(str(tmp_path))
yield str(tmp_path)

@pytest.fixture
def store(self, repo_path, branch, subdir_name):
Expand Down

0 comments on commit 6d1b31a

Please sign in to comment.