-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to turn off sorting keys in Dumper
- Loading branch information
1 parent
611ba39
commit 07c88c6
Showing
14 changed files
with
110 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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, Loader=yaml.FullLoader) | ||
dump_sorted = yaml.dump(data, default_flow_style=False, sort_keys=True) | ||
dump_unsorted = yaml.dump(data, default_flow_style=False, sort_keys=False) | ||
dump_unsorted = yaml.dump(data, default_flow_style=False, sort_keys=False, Dumper=yaml.SafeDumper) | ||
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()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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, Loader=yaml.FullLoader) | ||
dump_sorted = yaml.dump(data, default_flow_style=False, sort_keys=True) | ||
dump_unsorted = yaml.dump(data, default_flow_style=False, sort_keys=False) | ||
dump_unsorted_safe = yaml.dump(data, default_flow_style=False, sort_keys=False, Dumper=yaml.SafeDumper) | ||
if verbose: | ||
print("INPUT:") | ||
print(input) | ||
print("DATA:") | ||
print(data) | ||
|
||
assert dump_sorted == sorted | ||
|
||
if sys.version_info>=(3,7): | ||
assert dump_unsorted == input | ||
assert dump_unsorted_safe == input | ||
|
||
test_sort_keys.unittest = ['.sort', '.sorted'] | ||
|
||
if __name__ == '__main__': | ||
import test_appliance | ||
test_appliance.run(globals()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters