Beispiel #1
0
 def _testme(self, argv, expected_output, stdin=None, env=None):
     """ Helper test shortcut """
     with mock_environ(env or {}):
         result = render_command(os.getcwd(), env or {}, stdin, argv)
     if isinstance(result, bytes):
         result = result.decode('utf-8')
     self.assertEqual(result, expected_output)
Beispiel #2
0
 def _testme(self, argv, stdin=None, env=None):
     """ Helper test shortcut """
     result = render_command(os.getcwd(), env or {}, stdin, argv)
     if(isinstance(result, str)):
         self.assertEqual(self.expected_output, result)
     else:
         self.assertEqual(self.expected_output.encode('UTF-8'), result)
Beispiel #3
0
 def _testme(self, argv, stdin=None, env=None):
     """ Helper test shortcut """
     result = render_command(os.getcwd(), env or {}, stdin, argv)
     if (isinstance(result, str)):
         self.assertEqual(self.expected_output, result)
     else:
         self.assertEqual(self.expected_output.encode('UTF-8'), result)
Beispiel #4
0
 def _testme(self, argv, expected_output, stdin=None, env=None):
     """ Helper test shortcut """
     with mock_environ(env or {}):
         result = render_command(os.getcwd(), env or {}, stdin, argv)
     if isinstance(result, bytes):
         result = result.decode('utf-8')
     self.assertEqual(result, expected_output)
Beispiel #5
0
def core(config):
    if not config.mappings_file:
        mappings = prepare_file_mappings(config.templates_dir, config.data_dir,
                                         config.output_dir)
    else:
        mappings = json.load(config.mappings_file)
        validate(mappings, SCHEMA)
    for mapping in mappings:
        template_filepath = mapping['template']
        data_filepath = mapping.get('data')
        destination_filepath = mapping['destination']

        print('Process template: {}, data: {}, destination: {}'.format(
            template_filepath, data_filepath, destination_filepath))

        args = [template_filepath]
        if data_filepath:
            args.append(data_filepath)
        output = render_command(os.getcwd(), os.environ, sys.stdin, args)

        destination_dir = os.path.dirname(destination_filepath)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        with open(destination_filepath, 'w') as f:
            f.write(output)
Beispiel #6
0
 def _testme(self, argv, stdin=None, env=None):
     """ Helper test shortcut """
     self.assertEqual(self.expected_output,
                      render_command(os.getcwd(), env or {}, stdin, argv))