Exemple #1
0
 def test_yq(self):
     for input_format in "yaml", "xml", "toml":
         try:
             cli(["--help"], input_format=input_format)
         except SystemExit as e:
             self.assertEqual(e.code, 0)
     self.assertEqual(self.run_yq("{}", ["."]), "")
     self.assertEqual(
         self.run_yq("foo:\n bar: 1\n baz: {bat: 3}", [".foo.baz.bat"]), "")
     self.assertEqual(
         self.run_yq("[1, 2, 3]", ["--yaml-output", "-M", "."]),
         "- 1\n- 2\n- 3\n")
     self.assertEqual(
         self.run_yq("foo:\n bar: 1\n baz: {bat: 3}",
                     ["-y", ".foo.baz.bat"]), "3\n...\n")
     self.assertEqual(self.run_yq("[aaaaaaaaaa bbb]", ["-y", "."]),
                      "- aaaaaaaaaa bbb\n")
     self.assertEqual(
         self.run_yq("[aaaaaaaaaa bbb]", ["-y", "-w", "8", "."]),
         "- aaaaaaaaaa\n  bbb\n")
     self.assertEqual(
         self.run_yq('{"понедельник": 1}', ['.["понедельник"]']), "")
     self.assertEqual(
         self.run_yq('{"понедельник": 1}', ["-y", '.["понедельник"]']),
         "1\n...\n")
     self.assertEqual(
         self.run_yq("- понедельник\n- вторник\n", ["-y", "."]),
         "- понедельник\n- вторник\n")
Exemple #2
0
def set_djlab_config(key, value):
    config_file = getenv('DJLAB_CONFIG')
    f = io.StringIO()
    with redirect_stdout(f):
        try:
            cli(args=['-Y', f'. | .{key} = \"{value}\"', config_file])
        except SystemExit:
            pass
    with open(config_file, 'w') as out:
        out.write(f.getvalue())
Exemple #3
0
def get_djlab_config(key):
    f = io.StringIO()
    with redirect_stdout(f):
        try:
            cli(args=['-Y', '.{}'.format(key), getenv('DJLAB_CONFIG')])
        except SystemExit:
            pass
    if f.getvalue().find(': ') > -1:
        return f.getvalue()
    else:
        return f.getvalue().replace('\n', '').replace('\'', '').replace('...', '')
Exemple #4
0
 def run_yq(self, input_data, args, expect_exit_codes={os.EX_OK}, input_format="yaml"):
     stdin, stdout = sys.stdin, sys.stdout
     try:
         sys.stdin = io.StringIO(input_data)
         sys.stdout = io.BytesIO() if USING_PYTHON2 else io.StringIO()
         cli(args, input_format=input_format)
     except SystemExit as e:
         self.assertIn(e.code, expect_exit_codes)
     finally:
         result = sys.stdout.getvalue()
         if USING_PYTHON2:
             result = result.decode("utf-8")
         sys.stdin, sys.stdout = stdin, stdout
     return result