FlightDeck/utils/test.py

42 строки
1.3 KiB
Python
Исходник Обычный вид История

2010-10-20 20:35:11 +04:00
import os
from test_utils import TestCase as _TestCase
2010-11-02 14:05:20 +03:00
from django.conf import settings
2010-10-20 20:35:11 +04:00
2011-02-03 15:28:10 +03:00
def get_latest_sdk_dir():
sdks = os.listdir(os.path.join(settings.FRAMEWORK_PATH, 'lib'))
found = None
sdk_time = -1
for sdk in sdks:
if sdk != '__init__.py':
sdk_inf = os.stat(os.path.join(settings.FRAMEWORK_PATH, 'lib',
sdk))
if sdk_time < 0 or sdk_time < sdk_inf.st_ctime:
sdk_time = sdk_inf.st_ctime
found = sdk
return found
2010-10-20 20:35:11 +04:00
class TestCase(_TestCase):
"""
Base class for tests depending on existance of lib/jetpack-sdk
"""
2011-02-03 15:28:10 +03:00
def createCore(self, core_dir='jetpack-sdk'):
2010-10-20 20:35:11 +04:00
" discover the newest dir and link to it "
2010-10-20 20:58:24 +04:00
# find the newest SDK
2011-02-03 15:28:10 +03:00
self.sdk_filename = get_latest_sdk_dir()
2011-02-01 18:23:39 +03:00
self.sdk_path = os.path.join(settings.FRAMEWORK_PATH,
2011-02-03 15:28:10 +03:00
'lib/', core_dir)
2011-02-01 18:23:39 +03:00
sdk_orig = os.path.join(settings.FRAMEWORK_PATH, 'lib',
self.sdk_filename)
2010-10-20 20:35:11 +04:00
self.core_link_created = False
if not os.path.exists(self.sdk_path):
os.symlink(sdk_orig, self.sdk_path)
self.core_link_created = True
def deleteCore(self):
" remove symlink "
2010-10-20 20:58:24 +04:00
if not hasattr(self, 'core_link_created'):
2010-10-20 20:35:11 +04:00
return
if self.core_link_created:
os.remove(self.sdk_path)