From c99da5515b2e44fca5593688282e88310828554e Mon Sep 17 00:00:00 2001 From: Shichao An Date: Thu, 9 Jan 2014 20:18:42 -0500 Subject: [PATCH] Add TestConfig test case --- soundmeter/tests.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/soundmeter/tests.py b/soundmeter/tests.py index c4c7caa..f85f965 100644 --- a/soundmeter/tests.py +++ b/soundmeter/tests.py @@ -1,6 +1,7 @@ import os import signal import subprocess +import time from unittest import TestCase from scripttest import TestFileEnvironment from .command import setup_user_dir @@ -8,10 +9,12 @@ from .utils import create_executable +d = os.path.dirname(__file__) +PROJECT_PATH = os.path.abspath(os.path.join(d, os.pardir)) + + def create_run_script(): - d = os.path.dirname(__file__) - project_path = os.path.abspath(os.path.join(d, os.pardir)) - run_script = os.path.join(project_path, 'run.py') + run_script = os.path.join(PROJECT_PATH, 'run.py') content = '#!/usr/bin/env python\n' content += 'from soundmeter.meter import main\n\n\n' content += 'main()' @@ -67,12 +70,24 @@ def tearDown(self): class TestCommands(TestCase): def test_sigint(self): popen = subprocess.Popen(['./run.py']) + time.sleep(2) os.kill(popen.pid, signal.SIGINT) def test_arguments(self): popen = subprocess.Popen(['./run.py', '-t', '10000', '-a', 'stop']) + time.sleep(2) os.kill(popen.pid, signal.SIGINT) def test_daemon(self): - popen = subprocess.Popen(['./run.py', '-d']) - os.kill(popen.pid, signal.SIGINT) + popen = subprocess.Popen(['./run.py', '-d'], shell=True) + time.sleep(2) + popen.send_signal(signal.SIGINT) + + +class TestConfig(TestCase): + def test_config(self): + config = os.path.join(PROJECT_PATH, 'sample_config') + os.environ['SOUNDMETER_TEST_CONFIG'] = config + popen = subprocess.Popen(['./run.py'], env=os.environ.copy()) + time.sleep(2) + popen.send_signal(signal.SIGINT)