Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use mkdtemp() for testing

  • Loading branch information...
commit 27bf84220acf710fdb1b654888d3a1cf9ceefaa5 1 parent c189ebb
@jpscaletti jpscaletti authored
Showing with 14 additions and 19 deletions.
  1. +2 −1  tests/helpers.py
  2. +12 −18 tests/test_manage.py
View
3  tests/helpers.py
@@ -7,6 +7,7 @@
import shutil
from StringIO import StringIO
import sys
+from tempfile import mkdtemp
from clay import Clay
from clay.helpers import make_dirs, create_file
@@ -17,7 +18,7 @@
HTTP_OK = 200
HTTP_NOT_FOUND = 404
-TESTS = dirname(__file__)
+TESTS = mkdtemp()
SOURCE_DIR = join(TESTS, 'source')
BUILD_DIR = join(TESTS, 'build')
View
30 tests/test_manage.py
@@ -3,6 +3,7 @@
import os
import sys
+from tempfile import mkdtemp
import clay
from clay.manage import main, manager
@@ -11,23 +12,17 @@
from .helpers import *
-TEST_DIR = join(dirname(__file__), 'foobar')
-
-
-def teardown_module():
- remove_dir(TEST_DIR)
-
def test_has_main():
main()
def test_create_skeleton():
- make_dirs(TEST_DIR)
- sys.argv = [sys.argv[0], 'new', TEST_DIR]
+ test_dir = mkdtemp()
+ sys.argv = [sys.argv[0], 'new', test_dir]
manager.run()
- assert os.path.isdir(join(TEST_DIR, 'source'))
- remove_dir(TEST_DIR)
+ assert os.path.isdir(join(test_dir, 'source'))
+ remove_dir(test_dir)
def test_get_version():
@@ -54,21 +49,20 @@ def fake_run(self, **config):
assert port == config['port']
monkeypatch.setattr(Flask, 'run', fake_run)
- sys.argv = [sys.argv[0], 'run', dirname(__file__), str(host), str(port)]
+ sys.argv = [sys.argv[0], 'run', mkdtemp(), str(host), str(port)]
manager.run()
def test_can_build(c):
- make_dirs(TEST_DIR)
- make_dirs(TEST_DIR, 'source')
- sp = join(TEST_DIR, 'source', 'foo.txt')
- bp = join(TEST_DIR, 'build', 'foo.txt')
+ test_dir = mkdtemp()
+ make_dirs(test_dir, 'source')
+ sp = join(test_dir, 'source', 'foo.txt')
+ bp = join(test_dir, 'build', 'foo.txt')
create_file(sp, u'bar')
- sys.argv = [sys.argv[0], 'build', TEST_DIR]
+ sys.argv = [sys.argv[0], 'build', test_dir]
manager.run()
assert os.path.exists(bp)
-
- remove_dir(TEST_DIR)
+ remove_dir(test_dir)
Please sign in to comment.
Something went wrong with that request. Please try again.