def test_remove_quotes(self):
   errors = []
   self.assertEqual(String.remove_quotes('hello', print=errors.append),
                    'hello')
   self.assertEqual(String.remove_quotes('"hello"', print=errors.append),
                    'hello')
   self.assertEqual(String.remove_quotes('hello"', print=errors.append),
                    'hello"')
   self.assertEqual(errors, [])
Beispiel #2
0
 def test_remove_quotes(self):
     errors = []
     self.assertEqual(String.remove_quotes('hello', print=errors.append),
                      'hello')
     self.assertEqual(String.remove_quotes('"hello"', print=errors.append),
                      'hello')
     self.assertEqual(String.remove_quotes('hello"', print=errors.append),
                      'hello"')
     self.assertEqual(errors, [])
 def test_remove_quotes_error(self):
   errors = []
   self.assertEqual(String.remove_quotes('"hello', print=errors.append),
                    'hello')
   self.assertEqual(errors,
                    ['WARNING: line started with " but didn\'t end with one:',
                     '"hello'])
Beispiel #4
0
 def test_remove_quotes_error(self):
     errors = []
     self.assertEqual(String.remove_quotes('"hello', print=errors.append),
                      'hello')
     self.assertEqual(errors, [
         'WARNING: line started with " but didn\'t end with one:', '"hello'
     ])
def read_env_file(data, print=print):
    try:
        return json.loads(data)
    except ValueError:
        pass

    bad_lines = []
    results = {}
    for number, raw_line in enumerate(data.splitlines()):
        line = String.remove_comment(raw_line).strip()
        if line:
            match = ENV_LINE_MATCH.match(line)
            if match:
                name, value = match.groups()
                results[name.strip()] = String.remove_quotes(value.strip())
            else:
                bad_lines.append([number, raw_line])
    if bad_lines:
        warn("Didn't understand the following environment file lines:", print)
        for number, line in bad_lines:
            print("%d. >>> %s" % (number + 1, line))

    return results
Beispiel #6
0
def read_env_file(data, print=print):
    try:
        return json.loads(data)
    except ValueError:
        pass

    bad_lines = []
    results = {}
    for number, raw_line in enumerate(data.splitlines()):
        line = String.remove_comment(raw_line).strip()
        if line:
            match = ENV_LINE_MATCH.match(line)
            if match:
                name, value = match.groups()
                results[name.strip()] = String.remove_quotes(value.strip())
            else:
                bad_lines.append([number, raw_line])
    if bad_lines:
        warn("Didn't understand the following environment file lines:", print)
        for number, line in bad_lines:
            print('%d. >>> %s' % (number + 1, line))

    return results