| 1 |
import os |
|---|
| 2 |
import sys |
|---|
| 3 |
import tempfile |
|---|
| 4 |
|
|---|
| 5 |
current_dir = os.path.dirname(__file__) |
|---|
| 6 |
sys.path.insert(0, os.path.join(current_dir, '../../')) |
|---|
| 7 |
|
|---|
| 8 |
try: |
|---|
| 9 |
import subprocess |
|---|
| 10 |
except ImportError, ex: |
|---|
| 11 |
from cheesecake import subprocess |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
CHEESECAKE_PATH = os.path.abspath(os.path.join(current_dir, |
|---|
| 15 |
'../../cheesecake_index')) |
|---|
| 16 |
DATA_PATH = os.path.abspath(os.path.join(current_dir, '../data/')) |
|---|
| 17 |
NOSE_PATH = os.path.join(DATA_PATH, 'nose-0.8.3.tar.gz') |
|---|
| 18 |
PACKAGE_PATH = os.path.join(DATA_PATH, 'package2.tar.gz') |
|---|
| 19 |
INVALID_PACKAGE_PATH = os.path.join(DATA_PATH, 'invalid_package.tar.gz') |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
class FunctionalTest(object): |
|---|
| 23 |
def _run_cheesecake(self, arguments): |
|---|
| 24 |
self.stdout_fd, self.stdout_name = tempfile.mkstemp(prefix='functional') |
|---|
| 25 |
self.stderr_fd, self.stderr_name = tempfile.mkstemp(prefix='functional') |
|---|
| 26 |
self.process = subprocess.Popen('%s %s' % (CHEESECAKE_PATH, arguments), |
|---|
| 27 |
stdout=self.stdout_fd, |
|---|
| 28 |
stderr=self.stderr_fd, |
|---|
| 29 |
shell=True) |
|---|
| 30 |
self.return_code = self.process.wait() |
|---|
| 31 |
|
|---|
| 32 |
def _assert_success(self): |
|---|
| 33 |
# Check that Cheesecake exited sucessfully. |
|---|
| 34 |
print "Return code: %d" % self.return_code |
|---|
| 35 |
assert self.return_code == 0 |
|---|
| 36 |
|
|---|
| 37 |
# Check that Cheesecake didn't wrote anything into stderr. |
|---|
| 38 |
stderr_contents = read_file_contents(self.stderr_name) |
|---|
| 39 |
print "Stderr contents:\n***\n%s\n***\n" % stderr_contents |
|---|
| 40 |
assert stderr_contents == '' |
|---|
| 41 |
|
|---|
| 42 |
def _cleanup(self): |
|---|
| 43 |
os.unlink(self.stdout_name) |
|---|
| 44 |
os.unlink(self.stderr_name) |
|---|
| 45 |
|
|---|
| 46 |
def tearDown(self): |
|---|
| 47 |
self._cleanup() |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
def read_file_contents(filename): |
|---|
| 51 |
fd = file(filename) |
|---|
| 52 |
|
|---|
| 53 |
contents = fd.read() |
|---|
| 54 |
fd.close() |
|---|
| 55 |
|
|---|
| 56 |
return contents |
|---|