示例#1
0
def main():
    argument_parser = make_argument_parser()
    args = argument_parser.parse_args()

    if args.version:
        print(f'wfc {get_version()}')
        return 0

    try:
        if args.check_schema:
            validator = SchemaValidator()
            for script_file_name in args.check_schema:
                with open(script_file_name) as script_file:
                    validator.execute(load_compiled_script(script_file))
            return 0

        else:
            with core.CompilerContext(args) as context:
                rc = core.compile(context)
    except (FileNotFoundError, IsADirectoryError, NotADirectoryError,
            InvalidOutputFormat, SchemaViolationError) as ex:
        sys.stderr.write(f'{ex}\n')
        rc = getattr(ex, 'errno', 1)

    return rc
示例#2
0
文件: test_core.py 项目: wizeline/wfc
    def test_create_context_with_no_arguments(self):
        args = self.arg_parser.parse_args([])
        with core.CompilerContext(args) as context:
            self.assertIs(sys.stdout, context.get_output_file())
            self.assertIs(sys.stdin, context.get_input_file())
            self.assertEqual('2.2.0', context.get_output_version())
            self.assertEqual(os.path.abspath('.'),
                             context.get_work_directory())
            self.assertTrue(context.is_verbose())

            self.assertTrue(context.has_pending_sources())
            context.next()
            self.assertFalse(context.has_pending_sources())
示例#3
0
 def _compile_with_args(self, args):
     with core.CompilerContext(self.arg_parser.parse_args(args)) as context:
         context.set_quiet()
         return core.compile(context)
示例#4
0
文件: test_core.py 项目: wizeline/wfc
 def test_create_context_with_version_220(self):
     args = self.arg_parser.parse_args(['-v', '2.2.0'])
     with core.CompilerContext(args) as context:
         self.assertIs(context.get_version(), OutputVersion.V22)
示例#5
0
文件: test_core.py 项目: wizeline/wfc
 def test_create_context_with_bad_version(self):
     args = self.arg_parser.parse_args(['-v', '2.0.0'])
     with self.assertRaises(ValueError) as error:
         core.CompilerContext(args)
     self.assertEquals('\'2.0.0\' is not a valid OutputVersion',
                       str(error.exception))
示例#6
0
文件: test_core.py 项目: wizeline/wfc
 def test_create_context_with_bad_not_a_directory(self):
     args = self.arg_parser.parse_args(['-w', __file__])
     with self.assertRaises(NotADirectoryError):
         core.CompilerContext(args)
示例#7
0
文件: test_core.py 项目: wizeline/wfc
 def test_create_context_with_bad_workdirectory(self):
     args = self.arg_parser.parse_args(['-w', 'not-a-directory'])
     with self.assertRaises(FileNotFoundError):
         core.CompilerContext(args)