Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _load_and_dump_with_opened_files(self, filename, rmode='r', wmode='w',
**oopts):
cpath = os.path.join(self.workdir, filename)
with TT.open(cpath, 'w', **oopts) as out:
TT.dump(self.cnf, out)
self.assertTrue(_is_file_object(out))
self.assertEqual(out.mode, wmode)
with TT.open(cpath, 'rb', **oopts) as inp:
cnf1 = TT.single_load(inp)
self.assertTrue(_is_file_object(inp))
self.assertEqual(inp.mode, rmode)
cpair = (self.cnf, cnf1)
self.assertTrue(dicts_equal(*cpair), "%r vs. %r" % cpair)
def test_30_dump_and_multi_load__to_from_stream(self):
TT.dump(self.dic, self.a_path)
TT.dump(self.upd, self.b_path)
res = TT.multi_load([TT.open(self.a_path), TT.open(self.b_path)])
self.assert_dicts_equal(res, self.exp)
def test_11_dump_and_single_load__to_from_stream(self):
TT.dump(self.cnf, TT.open(self.a_path, mode='w'))
self.assertTrue(os.path.exists(self.a_path))
res = TT.single_load(TT.open(self.a_path))
self.assert_dicts_equal(res, self.cnf)
def _load_and_dump_with_opened_files(self, filename, rmode='r', wmode='w',
**oopts):
cpath = os.path.join(self.workdir, filename)
with TT.open(cpath, 'w', **oopts) as out:
TT.dump(self.cnf, out)
self.assertTrue(_is_file_object(out))
self.assertEqual(out.mode, wmode)
with TT.open(cpath, 'rb', **oopts) as inp:
cnf1 = TT.single_load(inp)
self.assertTrue(_is_file_object(inp))
self.assertEqual(inp.mode, rmode)
cpair = (self.cnf, cnf1)
self.assertTrue(dicts_equal(*cpair), "%r vs. %r" % cpair)
def test_15_single_load__fail_to_render_template(self):
if not anyconfig.template.SUPPORTED:
return
cnf_s = "name: '{{ name'" # Should cause template renering error.
cpath = os.path.join(self.workdir, "a.yaml")
TT.open(cpath, mode='w').write(cnf_s)
cnf = TT.single_load(cpath, ac_template=True, ac_context=dict(a=1))
self.assertEqual(cnf["name"], "{{ name")
def test_11_dump_and_single_load__to_from_stream(self):
TT.dump(self.cnf, TT.open(self.a_path, mode='w'))
self.assertTrue(os.path.exists(self.a_path))
res = TT.single_load(TT.open(self.a_path))
self.assert_dicts_equal(res, self.cnf)
def test_31_dump_and_load__to_from_stream(self):
with TT.open(self.a_path, mode='w') as strm:
TT.dump(self.dic, strm)
self.assertTrue(os.path.exists(self.a_path))
with TT.open(self.a_path) as strm:
res = TT.load(strm, ac_parser="json")
self.assert_dicts_equal(res, self.dic)