本文整理汇总了Python中testfixtures.TempDirectory.write方法的典型用法代码示例。如果您正苦于以下问题:Python TempDirectory.write方法的具体用法?Python TempDirectory.write怎么用?Python TempDirectory.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testfixtures.TempDirectory
的用法示例。
在下文中一共展示了TempDirectory.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPrepareTarget
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
class TestPrepareTarget(TestCase):
def setUp(self):
self.dir = TempDirectory()
self.addCleanup(self.dir.cleanup)
replace = Replacer()
replace('workfront.generate.TARGET_ROOT', self.dir.path)
self.addCleanup(replace.restore)
self.session = Session('test')
def test_from_scratch(self):
path = prepare_target(self.session)
compare(path, expected=self.dir.getpath('unsupported.py'))
self.dir.compare(expected=[])
def test_everything(self):
self.dir.write('unsupported.py', b'yy')
path = prepare_target(self.session)
compare(path, expected=self.dir.getpath('unsupported.py'))
self.dir.compare(expected=['unsupported.py'])
compare(self.dir.read('unsupported.py'), b"yy")
def test_dots_in_version(self):
path = prepare_target(Session('test', api_version='v4.0'))
compare(path, expected=self.dir.getpath('v40.py'))
self.dir.compare(expected=[])
示例2: test_evaluate_read_same
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def test_evaluate_read_same(self):
dir = TempDirectory()
dir.write('foo', b'content')
d = TestContainer('parsed',FileBlock('foo','content','read'))
d.evaluate_with(Files('td'),globs={'td':dir})
compare([C(FileResult,
passed=True,
expected=None,
actual=None)],
[r.evaluated for r in d])
示例3: test_evaluate_read_difference
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def test_evaluate_read_difference(self):
dir = TempDirectory()
dir.write('foo', b'actual')
d = TestContainer('parsed',FileBlock('foo','expected','read'))
d.evaluate_with(Files('td'),globs={'td':dir})
compare([C(FileResult,
passed=False,
path='foo',
expected='expected',
actual='actual')],
[r.evaluated for r in d])
示例4: test_inifile_discovery_should_ignore_invalid_files_without_raising_exception
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def test_inifile_discovery_should_ignore_invalid_files_without_raising_exception(self):
root_dir = TempDirectory()
self.tmpdirs.append(root_dir)
cfg_file = root_dir.write(('some', 'strange', 'config.cfg'), '&ˆ%$#$%ˆ&*()(*&ˆ'.encode('utf8'))
root_dir.write(('some', 'config.ini'), '$#%ˆ&*((*&ˆ%'.encode('utf8'))
discovery = ConfigurationDiscovery(
os.path.realpath(os.path.dirname(cfg_file)), filetypes=(IniFileConfigurationLoader, ))
self.assertEqual(discovery.config_files, [])
示例5: setUp
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
class TestFixtureLoad:
def setUp(self):
self.d = TempDirectory()
fixtureload.set_source_dir(self.d.path)
self.d.write('test.json',
json.dumps(
{
'description':
{
'samples': {
'fixture0': {'a': 'b'},
'fixture1': {'c': 'd'}
}
}
}
))
self.d.write('test_corrupted.json', 'corrupted json')
def tearDown(self):
self.d.cleanup()
def test_can_set_fixture_source_directory(self):
fixtureload.set_source_dir('/tmp')
assert fixtureload.fixture_source_dir == '/tmp'
def test_can_load_fixture(self):
fixture = fixtureload.load('test/description/fixture0')
compare(fixture, {'a': 'b'})
fixture = fixtureload.load('test/description/fixture1')
compare(fixture, {'c': 'd'})
def test_load_fixture_with_not_existed_file_should_raise(self):
with ShouldRaise(IOError):
fixtureload.load('not_existed/description/fixture0')
def test_load_fixture_with_corrupted_file_should_raise(self):
with ShouldRaise(ValueError):
fixtureload.load('test_corrupted/description/fixture0')
def test_parse_fixture_path(self):
path = fixtureload.parse_fixture_path('test/desc/fixture0')
compare(
path,
{
'source_file': 'test.json',
'fixture_desc': 'desc',
'fixture': 'fixture0'
}
)
def test_parse_fixture_path_if_path_is_not_valid(self):
with ShouldRaise(ValueError('Fixture Path is not valid (testfixture0)')):
fixtureload.parse_fixture_path('testfixture0')
示例6: HomeDirTest
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
class HomeDirTest(unittest.TestCase):
def setUp(self):
self.temp_dir = TempDirectory(create=True)
self.home = PathHomeDir(self.temp_dir.path)
def tearDown(self):
self.temp_dir.cleanup()
def test_read(self):
self.temp_dir.write("filename", "contents")
self.assertEquals(self.home.read("filename"), "contents")
def test_write(self):
self.temp_dir.write("existing_file", "existing_contents")
self.home.write("new_file", "contents")
self.home.write("existing_file", "new_contents")
self.assertEquals(self.temp_dir.read("existing_file"),
"new_contents")
self.assertEquals(self.temp_dir.read("new_file"), "contents")
def test_config_file(self):
with collect_outputs() as outputs:
self.home.write_config_file("new config")
self.temp_dir.check(".cosmosrc")
self.assertEquals(self.home.read_config_file(), "new config")
self.assertIn("Settings saved", outputs.stdout.getvalue())
file_mode = os.stat(self.temp_dir.getpath(".cosmosrc")).st_mode
self.assertEquals(file_mode, stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR)
def test_override_config_file(self):
with collect_outputs():
other_config = self.temp_dir.write("path/other", "config")
self.assertEquals(
self.home.read_config_file(filename_override=other_config),
"config")
def test_warn_on_unprotected_config_file(self):
with collect_outputs() as outputs:
self.home.write_config_file("new config")
config_path = self.temp_dir.getpath(".cosmosrc")
os.chmod(config_path, 0777)
self.home.read_config_file()
assertFunc = (self.assertNotIn if os.name=='nt' else self.assertIn)
assertFunc("WARNING", outputs.stderr.getvalue())
def test_last_cluster(self):
self.home.write_last_cluster("0000000")
self.temp_dir.check(".cosmoslast")
self.assertEquals(self.home.read_last_cluster(), "0000000")
示例7: test_cleanup
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def test_cleanup(self):
d = TempDirectory()
p = d.path
assert os.path.exists(p) is True
p = d.write('something', b'stuff')
d.cleanup()
assert os.path.exists(p) is False
示例8: TestPathSource
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
class TestPathSource(TestCase):
def setUp(self):
self.dir = TempDirectory()
self.addCleanup(self.dir.cleanup)
def test_abc(self):
self.assertTrue(issubclass(Plugin, Source))
def test_schema_ok(self):
p1 = self.dir.write('foo', b'f')
p2 = self.dir.write('bar', b'b')
compare(
dict(type='paths', values=[p1, p2], repo='config'),
Plugin.schema(
dict(type='paths', values=[p1, p2], repo='config')
))
def test_schema_wrong_type(self):
text = "not a valid value for dictionary value @ data['type']"
with ShouldFailSchemaWith(text):
Plugin.schema(dict(type='bar', values=['/']))
def test_schema_extra_keys(self):
with ShouldFailSchemaWith("extra keys not allowed @ data['foo']"):
Plugin.schema(dict(type='paths', foo='bar'))
def test_name_supplied(self):
text = "not a valid value for dictionary value @ data['name']"
with ShouldFailSchemaWith(text):
Plugin.schema(dict(type='paths', name='foo'))
def test_no_paths(self):
text = "length of value must be at least 1 for dictionary value " \
"@ data['values']"
with ShouldFailSchemaWith(text):
Plugin.schema(dict(type='paths', values=[]))
def test_path_not_string(self):
text = "invalid list value @ data['values'][0]"
with ShouldFailSchemaWith(text):
Plugin.schema(dict(type='paths', values=[1]))
def test_path_not_starting_with_slash(self):
text = "invalid list value @ data['values'][0]"
with ShouldFailSchemaWith(text):
Plugin.schema(dict(type='paths', values=['foo']))
def test_path_not_there(self):
text = "invalid list value @ data['values'][0]"
with ShouldFailSchemaWith(text):
Plugin.schema(dict(type='paths', values=[self.dir.getpath('bad')]))
def test_interface(self):
plugin = Plugin('source', name=None, repo='config',
values=['/foo/bar'])
compare(plugin.type, 'source')
compare(plugin.name, None)
compare(plugin.repo, 'config')
compare(plugin.source_paths, ['/foo/bar'])
示例9: Test_SnapshotArchive_Repository
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
class Test_SnapshotArchive_Repository(TestCase):
def setUp(self):
store = MemoryCommitStorage()
self.repo = BBRepository(store)
self.tempdir = TempDirectory()
self.setup_archive_a_snapshot()
def setup_archive_a_snapshot(self):
archive_name = 'somearchive.tgz'
self.archive_contents = '123'
self.archive_path = self.tempdir.write(archive_name,
self.archive_contents)
self.tag = generate_tag()
self.first_WAL = '01234'
self.last_WAL = '45678'
commit_snapshot_to_repository(self.repo, self.archive_path, self.tag,
self.first_WAL, self.last_WAL)
def tearDown(self):
self.tempdir.cleanup()
def test_can_retrieve_snapshot_contents_with_tag(self):
commit = [i for i in self.repo][-1]
restore_path = self.tempdir.getpath('restorearchive.tgz')
commit.get_contents_to_filename(restore_path)
self.assertEqual(self.archive_contents,
open(restore_path, 'rb').read())
def test_get_first_WAL_file_for_archived_snapshot_with_tag(self):
self.assertEqual(self.first_WAL, get_first_WAL(self.repo, self.tag))
def test_get_last_WAL_file_for_archived_snapshot_with_tag(self):
self.assertEqual(self.last_WAL, get_last_WAL(self.repo, self.tag))
示例10: test_testlist
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def test_testlist(self):
import stat
work_directory = TempDirectory()
work_directory.makedir('test')
work_directory.write(['test', 'test_dummy.c'], b'')
build_directory = TempDirectory()
testbin_path = build_directory.write(['test_dummy'], b'')
st = os.stat(testbin_path)
os.chmod(testbin_path, st.st_mode | stat.S_IEXEC)
w = Watcher(work_directory.path, build_directory.path)
w.poll()
exefile = testbin_path + watcher.EXE_SUFFIX
testlist = [(g.source(), g.executable()) for g in w.testlist()]
assert testlist == [(os.path.join('test', 'test_dummy.c'), exefile)]
示例11: setUp
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def setUp(self):
self.app = Flask(__name__)
self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
self.app.config['USER_LIST'] = ['Test Admin']
db.init_app(self.app)
d = TempDirectory()
d.makedir('dataset')
d.write('dataset/files/testfile.jpg', 'abc')
d.write('dataset/testfile2.jpg', 'abc')
self.directory = d
self.app.config['DATASET_ROOT'] = d.path
with self.app.app_context(), TempDirectory() as d:
db.create_all()
lib.models.buildDB()
dataset = lib.models.Datasets()
dataset.name = 'Test'
dataset.path = "dataset"
db.session.add(dataset)
db.session.commit()
示例12: test_poll
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def test_poll(self):
work_directory = TempDirectory()
work_directory.write('a.h', b'')
work_directory.write('a.c', b'')
work_directory.write('a.cc', b'')
work_directory.write('CMakeLists.txt', b'')
work_directory.write('blah.txt', b'')
w = Watcher(work_directory.path, None)
watchstate = w.poll()
assert watcher.has_changes(watchstate)
watchstate = w.poll()
assert not watcher.has_changes(watchstate)
work_directory.write('b.c', b'')
watchstate = w.poll()
assert watcher.has_changes(watchstate)
示例13: GitHelper
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
class GitHelper(object):
repo = 'local/'
def setUp(self):
self.dir = TempDirectory()
self.addCleanup(self.dir.cleanup)
def git(self, command, repo=None):
repo_path = self.dir.getpath(repo or self.repo)
try:
return check_output(['git'] + command.split(), cwd=repo_path, stderr=STDOUT)
except CalledProcessError as e:
self.fail(e.output)
def git_rev_parse(self, label, repo=None):
return self.git('rev-parse --verify -q --short '+label, repo).strip()
def check_tags(self, expected, repo=None):
actual = {}
for tag in self.git('tag', repo).split():
actual[tag] = self.git_rev_parse(tag, repo)
compare(expected, actual=actual)
def make_repo_with_content(self, repo):
if not os.path.exists(self.dir.getpath(repo)):
self.dir.makedir(repo)
self.git('init', repo)
self.dir.write(repo + 'a', 'some content')
self.dir.write(repo + 'b', 'other content')
self.dir.write(repo + 'c', 'more content')
self.git('add .', repo)
self.git('commit -m initial', repo)
示例14: TestRawConverter
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
class TestRawConverter(unittest.TestCase):
def setUp(self):
self.tmp = TempDirectory()
foo = self.tmp.write('foo.csv', b"1,2,3\n4,5,6\n7,8,9")
bar = self.tmp.write('bar.csv', b"9,8,7\n6,5,4\n3,2,1")
self.rawleft = self.tmp.write('P100_E4_left.dat',
b'\x05\x07\x3d\x08\xdd\x07\xf1\x06\x98\x06\x3a\x07')
self.rawright = self.tmp.write('P100_E4_right.dat',
b'\xe2\x06\x6b\x08\xe8\x07\x39\x07\xb1\x06\x48\x07')
self.foo = shared.UninitializedSensor._make([shared.Orientation(1), foo])
self.bar = shared.UninitializedSensor._make([shared.Orientation(2), bar])
def tearDown(self):
TempDirectory.cleanup_all()
def test_sensor_setup(self):
conv = RawConverter([], [self.foo, self.bar])
conv.processDatFiles()
self.assertIsInstance(conv.initSensors[
shared.Orientation(1).name], Sensor)
self.assertIsInstance(conv.initSensors[
shared.Orientation(2).name], Sensor)
self.assertEquals(conv.initSensors[
shared.Orientation(1).name].orientation, shared.Orientation(1))
self.assertEquals(conv.initSensors[
shared.Orientation(2).name].orientation, shared.Orientation(2))
def test_invalid_filesToConvert_parameter(self):
conv = RawConverter(
[self.rawleft, self.rawright], [self.foo, self.bar])
self.assertRaises(TypeError, conv.processDatFiles)
def test_dat_file_processing(self):
first = shared.Sourcefile._make(
[os.path.dirname(self.rawleft), 'P100_E4_left.dat', '01', '01', shared.Orientation(1)])
second = shared.Sourcefile._make(
[os.path.dirname(self.rawright), 'P100_E4_right.dat', '01', '01', shared.Orientation(2)])
conv = RawConverter(
[(first, second)], [self.foo, self.bar])
conv.processDatFiles()
示例15: setUp
# 需要导入模块: from testfixtures import TempDirectory [as 别名]
# 或者: from testfixtures.TempDirectory import write [as 别名]
def setUp(self):
data.app.config['TESTING'] = True
data.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
data.app.config['USER_LIST'] = ['Test Admin']
db.init_app(data.app)
d = TempDirectory()
d.makedir('dataset')
d.write('dataset/files/testfile.jpg', 'abc')
d.write('dataset/testfile2.jpg', 'abc')
self.directory = d
data.app.config['DATASET_ROOT'] = d.path
with data.app.app_context(), TempDirectory() as d:
db.create_all()
lib.models.buildDB()
license = lib.models.License.query.first()
provider = lib.models.Provider.query.first()
dataset = lib.models.Datasets()
dataset.name = 'Test'
dataset.license = [license]
dataset.provider = [provider]
dataset.path = "dataset"
db.session.add(dataset)
db.session.commit()
self.app = data.app.test_client()