Skip to content

Commit bf04183

Browse files
committed
use tempfile.gettempdir instead of hardcoded tmp
This means unit tests will work on non-Unix systems, and is just generally more correct.
1 parent 15bd78f commit bf04183

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

tests/apps/app/commands/test_new.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
import tempfile
34
from unittest import TestCase
45

56
from piccolo.apps.app.commands.new import new, module_exists
@@ -13,7 +14,7 @@ def test_module_exists(self):
1314

1415
class TestNewApp(TestCase):
1516
def test_new(self):
16-
root = "/tmp"
17+
root = tempfile.gettempdir()
1718
app_name = "my_app"
1819

1920
app_path = os.path.join(root, app_name)
@@ -30,7 +31,7 @@ def test_new_with_clashing_name(self):
3031
Test trying to create an app with the same name as a builtin Python
3132
package - it shouldn't be allowed.
3233
"""
33-
root = "/tmp"
34+
root = tempfile.gettempdir()
3435
app_name = "sys"
3536

3637
with self.assertRaises(SystemExit) as context:

tests/apps/asgi/commands/test_new.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
import tempfile
34
from unittest import TestCase
45
from unittest.mock import patch
56

@@ -15,7 +16,7 @@ class TestNewApp(TestCase):
1516
"piccolo.apps.asgi.commands.new.get_server", return_value=SERVERS[0],
1617
)
1718
def test_new(self, *args, **kwargs):
18-
root = "/tmp/asgi_app"
19+
root = os.path.join(tempfile.gettempdir(), "asgi_app")
1920

2021
if os.path.exists(root):
2122
shutil.rmtree(root)

tests/apps/migrations/commands/test_new.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
import tempfile
34
from unittest import TestCase
45
from unittest.mock import call, patch, MagicMock
56

@@ -20,8 +21,9 @@ def test_create_new_migration(self):
2021
"""
2122
Create a manual migration (i.e. non-auto).
2223
"""
23-
migration_folder = "/tmp/piccolo_migrations/"
24-
24+
migration_folder = os.path.join(
25+
tempfile.gettempdir(), "piccolo_migrations"
26+
)
2527
if os.path.exists(migration_folder):
2628
shutil.rmtree(migration_folder)
2729

tests/apps/project/commands/test_new.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import os
22
from unittest import TestCase
3+
import tempfile
34

45
from piccolo.apps.project.commands.new import new
56

67

78
class TestNewProject(TestCase):
89
def test_new(self):
9-
root = "/tmp"
10+
root = tempfile.gettempdir()
1011

11-
file_path = "/tmp/piccolo_conf.py"
12+
file_path = os.path.join(root, "piccolo_conf.py")
1213

1314
if os.path.exists(file_path):
1415
os.unlink(file_path)

0 commit comments

Comments
 (0)