Skip to content

Commit

Permalink
Add test for sort_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Mar 17, 2018
1 parent 92fa5a5 commit 06aa073
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/data/mapping.sort
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
z: 1
a: 2
y: 3
b: 4
x: 5
c: 6
6 changes: 6 additions & 0 deletions tests/data/mapping.sorted
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a: 2
b: 4
c: 6
x: 5
y: 3
z: 1
27 changes: 27 additions & 0 deletions tests/lib/test_sort_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import yaml
import pprint
import sys

def test_sort_keys(input_filename, sorted_filename, verbose=False):
input = open(input_filename, 'rb').read().decode('utf-8')
sorted = open(sorted_filename, 'rb').read().decode('utf-8')
data = yaml.load(input)
dump_sorted = yaml.dump(data, default_flow_style=False, sort_keys=True)
dump_unsorted = yaml.dump(data, default_flow_style=False, sort_keys=False)
if verbose:
print("INPUT:")
print(input)
print("DATA:")
print(data)

assert dump_sorted == sorted




test_sort_keys.unittest = ['.sort', '.sorted']

if __name__ == '__main__':
import test_appliance
test_appliance.run(globals())

27 changes: 27 additions & 0 deletions tests/lib3/test_sort_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import yaml
import pprint
import sys

def test_sort_keys(input_filename, sorted_filename, verbose=False):
input = open(input_filename, 'rb').read().decode('utf-8')
sorted = open(sorted_filename, 'rb').read().decode('utf-8')
data = yaml.load(input)
dump_sorted = yaml.dump(data, default_flow_style=False, sort_keys=True)
dump_unsorted = yaml.dump(data, default_flow_style=False, sort_keys=False)
if verbose:
print("INPUT:")
print(input)
print("DATA:")
print(data)

assert dump_sorted == sorted

if sys.version_info>=(3,7):
assert dump_unsorted == input

test_sort_keys.unittest = ['.sort', '.sorted']

if __name__ == '__main__':
import test_appliance
test_appliance.run(globals())

0 comments on commit 06aa073

Please sign in to comment.