本文整理汇总了Python中scripttest.TestFileEnvironment.clear方法的典型用法代码示例。如果您正苦于以下问题:Python TestFileEnvironment.clear方法的具体用法?Python TestFileEnvironment.clear怎么用?Python TestFileEnvironment.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scripttest.TestFileEnvironment
的用法示例。
在下文中一共展示了TestFileEnvironment.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestManagement
# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import clear [as 别名]
class TestManagement(TestCase):
@staticmethod
def _remvoe_db_file():
if os.path.exists(DB_PATH):
os.remove(DB_PATH)
def setUp(self):
# removes the database file
self._remvoe_db_file()
# sets up ScriptTest testing environement
self.env = TestFileEnvironment(
base_path = TESTS_OUTPUT_PATH,
start_clear = True,
)
os.chdir(TESTS_OUTPUT_PATH)
def tearDown(self):
# restores current directory
os.chdir(BASE_PATH)
# removes files created during the tests
self.env.clear()
# remove the test output folder
shutil.rmtree(TESTS_OUTPUT_PATH)
# removes the database file
self._remvoe_db_file()
def test_test_cmd(self):
r = self.env.run('%s test' % os.path.join(EXAMPLE_PATH, 'manage.py'))
self.assertEquals(r.stdout, "Hello world!\n")
def test_create_admin(self):
r = self.env.run('%s create_admin' % os.path.join(EXAMPLE_PATH, 'manage.py'))
self.assertEquals(r.stdout, "Admin user %(user)s (password: %(pwd)s) created successfully.\n" % {
'user': ADMIN_USER,
'pwd': ADMIN_PWD,
})
r = self.env.run('%s create_admin' % os.path.join(EXAMPLE_PATH, 'manage.py'))
self.assertEquals(r.stdout, "Admin user %(user)s already exists!\n" % {
'user': ADMIN_USER,
})
示例2: setup_class
# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import clear [as 别名]
class TestCLI:
""" Contains setups, teardowns, and tests for CLI
"""
@classmethod
def setup_class(cls):
""" Create a config file to read from """
with open(CONFIGFILE, 'w') as config:
config.write(CONFIG_YAML)
@classmethod
def teardown_class(cls):
""" Remove config file """
os.remove(CONFIGFILE)
def setup(self):
""" Create a file to print to and set up env"""
self.env = None
self.default_args = None
self.env = TestFileEnvironment(
base_path=TEST_DIR,
cwd=os.getcwd(),
)
self.default_args = (
'python-escpos',
'-c',
CONFIGFILE,
)
fhandle = open(DEVFILE, 'a')
try:
os.utime(DEVFILE, None)
finally:
fhandle.close()
def teardown(self):
""" Destroy printer file and env """
os.remove(DEVFILE)
self.env.clear()
def test_cli_help(self):
""" Test getting help from cli """
result = self.env.run('python-escpos', '-h')
assert not result.stderr
assert 'usage' in result.stdout
def test_cli_version(self):
""" Test the version string """
result = self.env.run('python-escpos', 'version')
assert not result.stderr
assert_equals(escpos.__version__, result.stdout.strip())
@nottest # disable this test as it is not that easy anymore to predict the outcome of this call
def test_cli_text(self):
""" Make sure text returns what we sent it """
test_text = 'this is some text'
result = self.env.run(
*(self.default_args + (
'text',
'--txt',
test_text,
))
)
assert not result.stderr
assert DEVFILE_NAME in result.files_updated.keys()
assert_equals(
result.files_updated[DEVFILE_NAME].bytes,
test_text + '\n'
)
def test_cli_text_inavlid_args(self):
""" Test a failure to send valid arguments """
result = self.env.run(
*(self.default_args + (
'text',
'--invalid-param',
'some data'
)),
expect_error=True,
expect_stderr=True
)
assert_equals(result.returncode, 2)
assert 'error:' in result.stderr
assert not result.files_updated
示例3: TestBamConverage
# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import clear [as 别名]
class TestBamConverage(unittest.TestCase):
'''Unit tests for bam_coverage.'''
def setUp(self):
self.env = TestFileEnvironment()
shutil.copytree(os.path.join(os.path.dirname(__file__), 'data'),
os.path.join(self.env.base_path, 'data'))
self.total = 237
self.coved = 154
self.fraction = 0.6497
self.min_match_coved = 115
self.min_match_fraction = 0.485
def tearDown(self):
self.env.clear()
def test_arguments(self):
ret = self.env.run("bioinfo", "-h")
self.assertEquals(ret.returncode, 0)
self.assertIn('bam_coverage', ret.stdout)
def test_complete_run_cli(self):
ret = self.env.run("bioinfo", "bam_coverage",
"data/bam_ref.fasta",
"data/bam_align.sorted.bam",
"10",
"--mapq=30", expect_stderr=True)
self.assertEquals(ret.returncode, 0)
self.assertIn('total bases in reference', ret.stdout)
self.assertIn('total ref bases covered', ret.stdout)
self.assertIn('fraction', ret.stdout)
self.assertNotIn('total bases in reference', ret.stderr)
self.assertNotIn('total ref bases covered', ret.stderr)
self.assertNotIn('fraction', ret.stderr)
for line in ret.stdout.split('\n'):
if 'total bases in reference' in line:
self.assertIn(str(self.total), line)
if 'total ref bases covered' in line:
self.assertIn(str(self.coved), ret.stdout)
if 'fraction' in line:
self.assertIn(str(self.fraction), ret.stdout)
def test_complete_run_module(self):
from bioinfo import bam_coverage
result = bam_coverage(
os.path.join('tests', 'data', 'bam_ref.fasta'),
os.path.join('tests', 'data', 'bam_align.sorted.bam'),
10,
30
)
self.assertEqual(result['total'], self.total)
self.assertEqual(result['covered'], self.coved)
self.assertAlmostEqual(result['fraction'], self.fraction, places=3)
def test_min_match(self):
from bioinfo import bam_coverage
result = bam_coverage(
os.path.join('tests', 'data', 'bam_ref.fasta'),
os.path.join('tests', 'data', 'bam_align.sorted.bam'),
45,
30
)
self.assertEqual(result['total'], self.total)
self.assertEqual(result['covered'], self.min_match_coved)
self.assertAlmostEqual(result['fraction'],
self.min_match_fraction,
places=2)
def test_check_dependencies(self):
import bioinfo
from bioinfo import bam_coverage
bioinfo.bam_coverage_mod.DEPENDENCIES['pysam'] = False
with self.assertRaises(SystemExit):
bam_coverage(
os.path.join('tests', 'data', 'bam_ref.fasta'),
os.path.join('tests', 'data', 'bam_align.sorted.bam'),
10,
30
)
bioinfo.bam_coverage_mod.DEPENDENCIES['pysam'] = True