当前位置: 首页>>代码示例>>Python>>正文


Python CSVValidator.add_unique_check方法代码示例

本文整理汇总了Python中csvvalidator.CSVValidator.add_unique_check方法的典型用法代码示例。如果您正苦于以下问题:Python CSVValidator.add_unique_check方法的具体用法?Python CSVValidator.add_unique_check怎么用?Python CSVValidator.add_unique_check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在csvvalidator.CSVValidator的用法示例。


在下文中一共展示了CSVValidator.add_unique_check方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_compound_unique_checks_with_variable_record_lengths

# 需要导入模块: from csvvalidator import CSVValidator [as 别名]
# 或者: from csvvalidator.CSVValidator import add_unique_check [as 别名]
def test_compound_unique_checks_with_variable_record_lengths():
    """Test the uniqueness checks on compound keys when record lengths vary."""

    field_names = ('something', 'foo', 'bar')
    validator = CSVValidator(field_names)
    validator.add_unique_check(('foo', 'bar'), 'X5', 'custom message')

    data = (
            ('something', 'foo', 'bar'),
            ('Z', '1', 'A'),
            ('Z', '2', 'B'),
            ('Z'),
            ('Z', '2', 'A'),
            ('Z', '1', 'A')
            )

    problems = validator.validate(data)
    print problems
    n = len(problems)
    assert n == 1, n

    p = problems[0]
    assert p['code'] == 'X5'
    assert p['message'] == 'custom message'
    assert p['row'] == 6
    assert p['key'] == ('foo', 'bar')
    assert p['value'] == ('1', 'A')
    assert p['record'] == ('Z', '1', 'A')
开发者ID:gamechanger,项目名称:csvvalidator,代码行数:30,代码来源:tests.py

示例2: test_unique_checks_with_variable_record_lengths

# 需要导入模块: from csvvalidator import CSVValidator [as 别名]
# 或者: from csvvalidator.CSVValidator import add_unique_check [as 别名]
def test_unique_checks_with_variable_record_lengths():
    """Test the uniqueness checks still work when record lengths vary."""

    field_names = ('foo', 'bar')
    validator = CSVValidator(field_names)
    validator.add_unique_check('bar')

    data = (
            ('foo', 'bar'),
            ('1', 'A'),
            ('2'),
            ('3', 'A')
            )

    problems = validator.validate(data)
    n = len(problems)
    assert n == 1, n

    p = problems[0]
    assert p['code'] == UNIQUE_CHECK_FAILED
    assert p['message'] == MESSAGES[UNIQUE_CHECK_FAILED]
    assert p['row'] == 4
    assert p['key'] == 'bar'
    assert p['value'] == 'A'
    assert p['record'] == ('3', 'A')
开发者ID:gamechanger,项目名称:csvvalidator,代码行数:27,代码来源:tests.py

示例3: test_compound_unique_checks

# 需要导入模块: from csvvalidator import CSVValidator [as 别名]
# 或者: from csvvalidator.CSVValidator import add_unique_check [as 别名]
def test_compound_unique_checks():
    """Test the uniqueness checks on compound keys."""

    field_names = ('foo', 'bar')
    validator = CSVValidator(field_names)
    validator.add_unique_check(('foo', 'bar'), 'X5', 'custom message')

    data = (
            ('foo', 'bar'),
            ('1', 'A'),
            ('2', 'B'),
            ('1', 'B'),
            ('2', 'A'),
            ('1', 'A')
            )

    problems = validator.validate(data)
    n = len(problems)
    assert n == 1, n

    p = problems[0]
    assert p['code'] == 'X5'
    assert p['message'] == 'custom message'
    assert p['row'] == 6
    assert p['key'] == ('foo', 'bar')
    assert p['value'] == ('1', 'A')
    assert p['record'] == ('1', 'A')
开发者ID:gamechanger,项目名称:csvvalidator,代码行数:29,代码来源:tests.py

示例4: test_unique_checks

# 需要导入模块: from csvvalidator import CSVValidator [as 别名]
# 或者: from csvvalidator.CSVValidator import add_unique_check [as 别名]
def test_unique_checks():
    """Test the uniqueness checks."""

    field_names = ('foo', 'bar')
    validator = CSVValidator(field_names)
    validator.add_unique_check('foo')

    data = (
            ('foo', 'bar'),
            ('1', 'A'),
            ('2', 'B'),
            ('1', 'C')
            )

    problems = validator.validate(data)
    n = len(problems)
    assert n == 1, n

    p = problems[0]
    assert p['code'] == UNIQUE_CHECK_FAILED
    assert p['message'] == MESSAGES[UNIQUE_CHECK_FAILED]
    assert p['row'] == 4
    assert p['key'] == 'foo'
    assert p['value'] == '1'
    assert p['record'] == ('1', 'C')
开发者ID:gamechanger,项目名称:csvvalidator,代码行数:27,代码来源:tests.py


注:本文中的csvvalidator.CSVValidator.add_unique_check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。