def test_error_required(self):
        # Test that error value is received when missing
        # required arguments
        link_path = os.path.join(FILES, 'link.yaml')
        config_path_1 = os.path.join(FILES, 'config_fail_2_1.yaml')
        config_path_2 = os.path.join(FILES, 'config_fail_2_2.yaml')
        config_path_3 = os.path.join(FILES, 'config_fail_2_3.yaml')

        result_1 = validate(link_path, config_path_1)
        result_2 = validate(link_path, config_path_2)
        result_3 = validate(link_path, config_path_3)

        self.assertEqual(result_1, 1)
        self.assertEqual(result_2, 1)
        self.assertEqual(result_3, 1)
    def test_error_everything(self):
        # Test that error value is received empty.
        link_path = os.path.join(FILES, 'link.yaml')
        config_path = os.path.join(FILES, 'config_fail_1.yaml')

        result = validate(link_path, config_path)

        self.assertEqual(result, 1)
    def test_error_exclusive(self):
        # Test that error value is received when
        # no required exclusive is entered
        link_path = os.path.join(FILES, 'link.yaml')
        config_path = os.path.join(FILES, 'config_fail_5.yaml')

        result = validate(link_path, config_path)

        self.assertEqual(result, 1)
    def test_error_optional_exclusive(self):
        # Test that error value is received when
        # too many optional exclusives are filled in.
        link_path = os.path.join(FILES, 'link.yaml')
        config_path = os.path.join(FILES, 'config_fail_4.yaml')

        result = validate(link_path, config_path)

        self.assertEqual(result, 1)
    def test_error_required_exlusive(self):
        # Test that error value is received when
        # when too many exlcusives are filled
        link_path = os.path.join(FILES, 'link.yaml')
        config_path = os.path.join(FILES, 'config_fail_3.yaml')

        result = validate(link_path, config_path)

        self.assertEqual(result, 1)
    def test_pass_optional_exlcusive(self):
        # Tests a passing scenario with
        # optional exclusive filled correctly
        link_path = os.path.join(FILES, 'link.yaml')
        config_path = os.path.join(FILES, 'config_pass_3.yaml')

        result = validate(link_path, config_path)

        self.assertEqual(result, 0)
    def test_pass_full(self):
        # Test's a passing scenario with optionals
        # exlcusives, and optional exclusives all
        # filled correctly.
        link_path = os.path.join(FILES, 'link.yaml')
        config_path = os.path.join(FILES, 'config_pass_1.yaml')

        result = validate(link_path, config_path)

        self.assertEqual(result, 0)
    def test_error_missing_element(self):
        # Test that error value is received when
        # config file is fundamentally changed.
        # ex: entire argument is removed.
        link_path = os.path.join(FILES, 'link.yaml')
        config_path = os.path.join(FILES, 'config_fail_6.yaml')

        result = validate(link_path, config_path)

        self.assertEqual(result, 1)
示例#9
0
def build(link_file_path, config_file_path, output):
    if not (link_file_path.endswith('.yaml')
            or config_file_path.endswith('.yaml')):
        click.secho(
            'Invalid filetype, please provide a .yml or .yaml link '
            'file',
            fg='red',
            err=True,
            bold=True)
        click.get_current_context().exit(1)

    try:
        link_file = LinkFile(link_file_path)
        config_file = ConfigFile(config_file_path)
        if validate(link_file_path, config_file_path):
            click.secho('Invalid configuration file.', fg='red', err=True)
            click.get_current_context().exit(1)

        # TODO: REMOVE THIS AWFUL HACK
        with open(link_file_path) as fh1, open(config_file_path) as fh2:
            result = branching(yaml.load(fh2.read()), yaml.load(fh1.read()),
                               os.getcwd())

        def _add_repr(dumper, value):
            return dumper.represent_scalar(u'tag:yaml.org,2002:null', '')

        yaml.SafeDumper.add_representer(type(None), _add_repr)

        with open('blah.yaml', 'w+') as fh:
            yaml.safe_dump(result, fh, default_flow_style=False)

        config_file = ConfigFile('blah.yaml')
        generate_luigi(config_file, link_file)
    except (ValueError, RuntimeError) as e:
        click.secho(str(e), fg='red', err=True, bold=True)
        click.get_current_context().exit(1)