Sequences of unique items (UniqueSeq)

UniqueSeq validates sequences which contain no duplicate values.

Example yaml_snippet:

- A
- B
- C
from strictyaml import UniqueSeq, Str, load, as_document
from ensure import Ensure

schema = UniqueSeq(Str())

Valid:

Ensure(load(yaml_snippet, schema)).equals(["A", "B", "C", ])

Parsing with one dupe raises an exception:

- A
- B
- B
load(yaml_snippet, schema)
strictyaml.exceptions.YAMLValidationError:
while parsing a sequence
  in "<unicode string>", line 1, column 1:
    - A
     ^ (line: 1)
duplicate found
  in "<unicode string>", line 3, column 1:
    - B
    ^ (line: 3)

Parsing all dupes raises an exception:

- 3
- 3
- 3
load(yaml_snippet, schema)
strictyaml.exceptions.YAMLValidationError:
while parsing a sequence
  in "<unicode string>", line 1, column 1:
    - '3'
     ^ (line: 1)
duplicate found
  in "<unicode string>", line 3, column 1:
    - '3'
    ^ (line: 3)

Serializing with dupes raises an exception:

as_document(["A", "B", "B"], schema)
strictyaml.exceptions.YAMLSerializationError:
Expecting all unique items, but duplicates were found in '['A', 'B', 'B']'.

Executable specification

Documentation automatically generated from unique-sequence.story storytests.