mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-29 06:51:08 -05:00
Create temporary files in a temporary directory
But keep it if tests fail. Closes #1061
This commit is contained in:
parent
ca8565b6d8
commit
03a3777129
@ -36,6 +36,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
started = time.time()
|
started = time.time()
|
||||||
|
|
||||||
import supybot
|
import supybot
|
||||||
@ -43,16 +44,19 @@ import logging
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
# We need to do this before we import conf.
|
# We need to do this before we import conf.
|
||||||
if not os.path.exists('test-conf'):
|
main_temp_dir = TemporaryDirectory()
|
||||||
os.mkdir('test-conf')
|
|
||||||
|
|
||||||
registryFilename = os.path.join('test-conf', 'test.conf')
|
os.makedirs(os.path.join(main_temp_dir.name, 'conf'))
|
||||||
fd = open(registryFilename, 'w')
|
os.makedirs(os.path.join(main_temp_dir.name, 'data'))
|
||||||
|
os.makedirs(os.path.join(main_temp_dir.name, 'logs'))
|
||||||
|
|
||||||
|
registryFilename = os.path.join(main_temp_dir.name, 'conf', 'test.conf')
|
||||||
|
with open(registryFilename, 'w') as fd:
|
||||||
fd.write("""
|
fd.write("""
|
||||||
supybot.directories.backup: /dev/null
|
supybot.directories.backup: /dev/null
|
||||||
supybot.directories.conf: %(base_dir)s/test-conf
|
supybot.directories.conf: {temp_conf}
|
||||||
supybot.directories.data: %(base_dir)s/test-data
|
supybot.directories.data: {temp_data}
|
||||||
supybot.directories.log: %(base_dir)s/test-logs
|
supybot.directories.log: {temp_logs}
|
||||||
supybot.reply.whenNotCommand: True
|
supybot.reply.whenNotCommand: True
|
||||||
supybot.log.stdout: False
|
supybot.log.stdout: False
|
||||||
supybot.log.stdout.level: ERROR
|
supybot.log.stdout.level: ERROR
|
||||||
@ -67,8 +71,11 @@ supybot.networks.testnet2.server: should.not.need.this
|
|||||||
supybot.networks.testnet3.server: should.not.need.this
|
supybot.networks.testnet3.server: should.not.need.this
|
||||||
supybot.nick: test
|
supybot.nick: test
|
||||||
supybot.databases.users.allowUnregistration: True
|
supybot.databases.users.allowUnregistration: True
|
||||||
""" % {'base_dir': os.getcwd()})
|
""".format(
|
||||||
fd.close()
|
temp_conf=os.path.join(main_temp_dir.name, 'conf'),
|
||||||
|
temp_data=os.path.join(main_temp_dir.name, 'data'),
|
||||||
|
temp_logs=os.path.join(main_temp_dir.name, 'logs')
|
||||||
|
))
|
||||||
|
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
registry.open_registry(registryFilename)
|
registry.open_registry(registryFilename)
|
||||||
@ -251,6 +258,9 @@ def main():
|
|||||||
if result.wasSuccessful():
|
if result.wasSuccessful():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
|
# Deactivate autocleaning for the temporary directiories to allow inspection.
|
||||||
|
main_temp_dir._finalizer.detach()
|
||||||
|
print(f"Temporary directory path: {main_temp_dir.name}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user