Commit 170d827e authored by Matěj Cepl's avatar Matěj Cepl

Input/Read test succeed!

parent 91e4adcb
#!/usr/bin/python
import yaml
IN = {
"name": 'Hello World 6',
"in": [
"---",
"- \"\\z\\x01\\x02\\x03\\x04\\x05\\x06\\a\\x08\\t\\n\\v\\f\\r\\x0e\\x0f\"",
"- \"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\e\\x1c\\x1d\\x1e\\x1f\"",
"- \" !\\\"#\$%&'()*+,-./\"",
"- 0123456789:;<=>?",
"- '\@ABCDEFGHIJKLMNO'",
"- 'PQRSTUVWXYZ[\\]^_'",
"- '`abcdefghijklmno'",
"- 'pqrstuvwxyz{|}~\177'",
"- \200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
"- \220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
"- \240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
"- \260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
"- \300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
"- \320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
"- \340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
"- \360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377",
"..."],
"out": [
"\0\1\2\3\4\5\6\a\b\t\n\13\f\r\16\17",
"\20\21\22\23\24\25\26\27\30\31\32\e\34\35\36\37",
" !\"#\$%&'()*+,-./",
"0123456789:;<=>?",
"\@ABCDEFGHIJKLMNO",
"PQRSTUVWXYZ[\\]^_",
"`abcdefghijklmno",
"pqrstuvwxyz{|}~\177",
"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
"\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
"\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
"\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
"\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
"\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
"\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
]
}
instr = "\n".join(IN['in'])
print "type instr = %s" % type(instr)
print instr
res = yaml.load(instr, Loader=yaml.SafeLoader)
print "'%s'" % (res == IN['out'])
This diff is collapsed.
/*
** MediaWiki Print style sheet for CSS2-capable browsers.
** Copyright Gabriel Wicke, http://www.aulinx.de/
**
** Derived from the plone (http://plone.org/) styles
** Copyright Alexander Limi
*/
/* Thanks to A List Apart (http://alistapart.com/) for useful extras */
a.stub,
a.new{ color:#ba0000; text-decoration:none; }
#toc {
/*border:1px solid #2f6fab;*/
border:1px solid #aaaaaa;
background-color:#f9f9f9;
padding:5px;
}
.tocindent {
margin-left: 2em;
}
.tocline {
margin-bottom: 0px;
}
/* images */
div.floatright {
float: right;
clear: right;
margin: 0;
position:relative;
border: 0.5em solid White;
border-width: 0.5em 0 0.8em 1.4em;
}
div.floatright p { font-style: italic;}
div.floatleft {
float: left;
margin: 0.3em 0.5em 0.5em 0;
position:relative;
border: 0.5em solid White;
border-width: 0.5em 1.4em 0.8em 0;
}
div.floatleft p { font-style: italic; }
/* thumbnails */
div.thumb {
margin-bottom: 0.5em;
border-style: solid; border-color: White;
width: auto;
overflow: hidden;
}
div.thumb div {
border:1px solid #cccccc;
padding: 3px !important;
background-color:#f9f9f9;
font-size: 94%;
text-align: center;
}
div.thumb div a img {
border:1px solid #cccccc;
}
div.thumb div div.thumbcaption {
border: none;
padding: 0.3em 0 0.1em 0;
}
div.magnify { display: none; }
div.tright {
float: right;
clear: right;
border-width: 0.5em 0 0.8em 1.4em;
}
div.tleft {
float: left;
margin-right:0.5em;
border-width: 0.5em 1.4em 0.8em 0;
}
/* table standards */
table.rimage {
float:right;
width:1pt;
position:relative;
margin-left:1em;
margin-bottom:1em;
text-align:center;
}
body {
background: White;
/*font-size: 11pt !important;*/
color: Black;
margin: 0;
padding: 0;
}
.noprint,
div#jump-to-nav,
div.top,
div#column-one,
#colophon,
.editsection,
.toctoggle,
.tochidden,
div#f-poweredbyico,
div#f-copyrightico,
li#viewcount,
li#about,
li#disclaimer,
li#privacy {
/* Hides all the elements irrelevant for printing */
display: none;
}
ul {
list-style-type: square;
}
#content {
background: none;
border: none ! important;
padding: 0 ! important;
margin: 0 ! important;
}
#footer {
background : white;
color : black;
border-top: 1px solid black;
}
h1, h2, h3, h4, h5, h6
{
font-weight: bold;
}
p, .documentDescription {
margin: 1em 0 ! important;
line-height: 1.2em;
}
.tocindent p {
margin: 0 0 0 0 ! important;
}
pre {
border: 1pt dashed black;
white-space: pre;
font-size: 8pt;
overflow: auto;
padding: 1em 0;
background : white;
color : black;
}
table.listing,
table.listing td {
border: 1pt solid black;
border-collapse: collapse;
}
a {
color: Black !important;
background: none !important;
padding: 0 !important;
}
a:link, a:visited {
color: #520;
background: transparent;
text-decoration: underline;
}
#content a.external.text:after, #content a.external.autonumber:after {
/* Expand URLs for printing */
content: " (" attr(href) ") ";
}
#globalWrapper {
width: 100% !important;
min-width: 0 !important;
}
#content {
background : white;
color : black;
}
#column-content {
margin: 0 !important;
}
#column-content #content {
padding: 1em;
margin: 0 !important;
}
/* MSIE/Win doesn't understand 'inherit' */
a, a.external, a.new, a.stub {
color: black ! important;
text-decoration: none ! important;
}
/* Continue ... */
a, a.external, a.new, a.stub {
color: inherit ! important;
text-decoration: inherit ! important;
}
img { border: none; }
img.tex { vertical-align: middle; }
span.texhtml { font-family: serif; }
div.townBox {
position:relative;
float:right;
background:White;
margin-left:1em;
border: 1px solid gray;
padding:0.3em;
width: 200px;
overflow: hidden;
clear: right;
}
div.townBox dl {
padding: 0;
margin: 0 0 0.3em 0;
font-size: 96%;
}
div.townBox dl dt {
background: none;
margin: 0.4em 0 0 0;
}
div.townBox dl dd {
margin: 0.1em 0 0 1.1em;
background-color: #f3f3f3;
}
#siteNotice { display: none; }
table.gallery {
border: 1px solid #cccccc;
margin: 2px;
padding: 2px;
background-color:#ffffff;
}
table.gallery tr {
vertical-align:top;
}
div.gallerybox {
border: 1px solid #cccccc;
margin: 2px;
background-color:#f9f9f9;
width: 150px;
}
div.gallerybox div.thumb {
text-align: center;
border: 1px solid #cccccc;
margin: 2px;
}
div.gallerytext {
font-size: 94%;
padding: 2px 4px;
}
/*
** Diff rendering
*/
table.diff { background:white; }
td.diff-otitle { background:#ffffff; }
td.diff-ntitle { background:#ffffff; }
td.diff-addedline {
background:#ccffcc;
font-size: smaller;
border: solid 2px black;
}
td.diff-deletedline {
background:#ffffaa;
font-size: smaller;
border: dotted 2px black;
}
td.diff-context {
background:#eeeeee;
font-size: smaller;
}
.diffchange {
color: silver;
font-weight: bold;
text-decoration: underline;
}
This diff is collapsed.
/* generated javascript */
var skin = 'monobook';
var stylepath = '/wiki/skins';
/* MediaWiki:Common.js */
/* Any JavaScript here will be loaded for all users on every page load. */
/* MediaWiki:Monobook.js (deprecated; migrate to Common.js!) */
/* Deprecated; use [[MediaWiki:common.js]] */
\ No newline at end of file
This diff is collapsed.
#!/usr/bin/perl -Wall
use strict;
use warnings;
use Data::YAML::Reader;
my %test = (
name => "Unprintables",
in => [
"---",
"- \"\\z\\x01\\x02\\x03\\x04\\x05\\x06\\a\\x08\\t\\n\\v\\f\\r\\x0e\\x0f\"",
"- \"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\e\\x1c\\x1d\\x1e\\x1f\"",
"- \" !\\\"#\$%&'()*+,-./\"",
"- 0123456789:;<=>?",
"- '\@ABCDEFGHIJKLMNO'",
"- 'PQRSTUVWXYZ[\\]^_'",
"- '`abcdefghijklmno'",
"- 'pqrstuvwxyz{|}~\177'",
"- \200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
"- \220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
"- \240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
"- \260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
"- \300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
"- \320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
"- \340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
"- \360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377",
"..."
],
out => [
"\0\1\2\3\4\5\6\a\b\t\n\13\f\r\16\17",
"\20\21\22\23\24\25\26\27\30\31\32\e\34\35\36\37",
" !\"#\$%&'()*+,-./",
"0123456789:;<=>?",
"\@ABCDEFGHIJKLMNO",
"PQRSTUVWXYZ[\\]^_",
"`abcdefghijklmno",
"pqrstuvwxyz{|}~\177",
"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",
"\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",
"\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",
"\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",
"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",
"\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",
"\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",
"\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
],
);
sub iter {
my $ar = shift;
return sub {
return shift @$ar;
};
}
my $yaml = Data::YAML::Reader->new;
my $source = join( "\n", @{ $test{in} } ) . "\n";
my $iter = iter( $test{in} );
my $got = $yaml->read($iter) ;
use Test::More tests => 1;
unless ( is_deeply $got, $test{out}, "Result matches" ) {
local $Data::Dumper::Useqq = $Data::Dumper::Useqq = 1;
diag( Data::Dumper->Dump( [$got], ['$got'] ) );
diag( Data::Dumper->Dump( [$test{out}], ['$expected'] ) );
}
\ No newline at end of file
def TODO(func):
"""unittest test method decorator that ignores
exceptions raised by test
Used to annotate test methods for code that may
not be written yet. Ignores failures in the
annotated test method; fails if the text
unexpectedly succeeds.
"""
def wrapper(*args, **kw):
try:
func(*args, **kw)
succeeded = True
except:
succeeded = False
assert succeeded is False, \
"%s marked TODO but passed" % func.__name__
wrapper.__name__ = func.__name__
wrapper.__doc__ = func.__doc__
return wrapper
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import logging
from test import test_reader, test_input
import yamlish
import unittest
import yaml
logging.basicConfig(level=logging.DEBUG)
def generate_test_name(source):
out = source.replace(' ', '_').replace(':', '').lower()
return "test_%s" % out
def create_test(test_src, tested_function):
def do_test_expected(self):
#self.assertEqual(under_test(pair[0]), pair[1])
if ('skip' in test_src) and test_src['skip']:
logging.info("test_src skipped!")
return
# rather keep original tests in lists even though we could
# do multiline strings
source = "\n".join(test_src['in']) + "\n"
logging.debug("source = %s", source)
got = ""
if 'error' in test_src:
self.assertRaises(test_src['error'], tested_function, test_src['in'])
else:
want = test_src['out']
got = tested_function(test_src['in'])
logging.debug("test_src['out'] = %s", unicode(test_src['out']))
self.assertEqual(got, want, """Result matches
expected = %s
observed = %s
""" % (want, got))
return do_test_expected
def generate_testsuite(test_data, test_case_shell, test_fce):
for in_test in test_data:
if ('skip' in in_test) and in_test['skip']:
logging.info("test %s skipped!", in_test['name'])
continue
name = generate_test_name(in_test['name'])
test_method = create_test (in_test, test_fce)
test_method.__name__ = str('test_%s' % name)
setattr (test_case_shell, test_method.__name__, test_method)
class TestInput(unittest.TestCase):
pass
class TestReader(unittest.TestCase):
pass
if __name__ == "__main__":
generate_testsuite(test_reader.test_data_list, TestReader, yamlish.load)
generate_testsuite(test_input.test_data_list, TestInput, yamlish.load)
unittest.main()
import sys
import os.path
sys.path.insert(0, os.path.realpath(os.path.dirname(__file__) + "/.."))
import logging
logging.basicConfig(level=logging.INFO)
import unittest
import test_load
import test_input
#import test_reader
import test_reader
import test_output
#import test_writer
import test_writer
if __name__ == "__main__":
loader = unittest.TestLoader()
suite = loader.loadTestsFromModule(test_load)
suite.addTests(loader.loadTestsFromModule(test_input))
#suite.addTests(loader.loadTestsFromModule(test_reader))
suite.addTests(loader.loadTestsFromModule(test_output))
#suite.addTests(loader.loadTestsFromModule(test_input))
suite.addTests(loader.loadTestsFromModule(test_reader))
#suite.addTests(loader.loadTestsFromModule(test_output))
#suite.addTests(loader.loadTestsFromModule(test_writer))
runner = unittest.TextTestRunner(verbosity=2)
......
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import logging
import unittest
import yamlish
logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
level=logging.INFO)
IN = """
---
bill-to:
address:
city: "Royal Oak"
lines: "458 Walkman Dr.\nSuite #292\n"
postal: 48046
state: MI
family: Dumars
given: Chris
comments: "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n"
date: 2001-01-23
invoice: 34843
product:
-
description: Basketball
price: 450.00
quantity: 4
sku: BL394D
-
description: "Super Hoop"
price: 2392.00
quantity: 1
sku: BL4438H
tax: 251.42
total: 4443.52
...
"""
OUT = {
'bill-to': {
'given': 'Chris',
'address': {
'city': 'Royal Oak',
'postal': '48046',
'lines': "458 Walkman Dr.\nSuite #292\n",
'state': 'MI'
},
'family': 'Dumars'
},
'invoice': '34843',
'date': '2001-01-23',
'tax': '251.42',
'product': [
test_data_list = [
{
'sku': 'BL394D',
'quantity': '4',
'price': '450.00',
'description': 'Basketball'
},
{
'sku': 'BL4438H',
'quantity': '1',
'price': '2392.00',
'description': 'Super Hoop'
}
],
'comments':
"Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n",
'total': '4443.52'
}
class TestInput(unittest.TestCase):
"""FIXME description of this class"""
def test_reader(self):
scalar = IN
source = [
"name": "Input test",
"in": """---
bill-to:
address:
city: "Royal Oak"
lines: "458 Walkman Dr.\\nSuite #292\\n"
postal: 48046
state: MI
family: Dumars
given: Chris
comments: "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\\n"
date: 2001-01-23
invoice: 34843
product:
-
description: Basketball
price: 450.00
quantity: 4
sku: BL394D
-
description: "Super Hoop"
price: 2392.00
quantity: 1
sku: BL4438H
tax: 251.42
total: 4443.52
...
""",
'out': {
'bill-to': {
'given': 'Chris',
'address': {
'city': 'Royal Oak',
'postal': 48046,
'lines': "458 Walkman Dr.\nSuite #292\n",
'state': 'MI'
},
'family': 'Dumars'
},
'invoice': 34843,
'date': '2001-01-23',
'tax': 251.42,
'product': [
{
"name": 'Array reference',
"source": IN.split("\n"),
'sku': 'BL394D',
'quantity': 4,
'price': 450.00,
'description': 'Basketball'
},
# {
# "name": 'Closure',
# "source": sub { shift @lines },
# },
{
"name": 'Scalar',
"source": IN,
'sku': 'BL4438H',
'quantity': 1,
'price': 2392.00,
'description': 'Super Hoop'
}
]
for src in source:
name = src['name']
yaml = yamlish.Reader()
self.assert_(True, "%s: Created" % name)
self.assert_(isinstance(yaml, yamlish.Reader))
#my $got = eval { $yaml -> read($src -> {source}) };
try:
got = yaml.read(src['source'])
except IOError: # FIXME not sure which one
raise
self.assertEqual(got, OUT, """%s: Result matches
expected = %s
observed = %s
""" % (name, OUT, got))
],
'comments':
"Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n",
'total': 4443.52
}
}
]
......@@ -4,11 +4,9 @@ import unittest
class TestBasics(unittest.TestCase):
def test_import(self):
import yamlish
from yamlish import Reader
self.assert_(True, "Importing Reader.")
from yamlish import Writer
self.assert_(True, "Importing Writer.")
self.assert_(True,
from yamlish import Reader #IGNORE:W0612
from yamlish import Writer #IGNORE:W0612
self.assertTrue(yamlish.__version__,
"Testing import of yamlish, version %s." % yamlish.__version__)
if __name__ == "__main__":
......
......@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import re
import unittest
import yamlish
from . import TODO
import yaml
OUT = [
"---",
......@@ -74,7 +74,7 @@ destination = [
{
"name": 'Array reference',
"destination": buf1,
"normalise": (lambda x: buf1),
"normalise": (lambda : buf1),
},
# {
# "name": 'Closure',
......@@ -89,15 +89,11 @@ destination = [
]