doctest
複数の行を含み、先頭に空の行が含まれている可能性がある結果を処理することができません。これはおそらく、インデントと解析の問題が原因です。私はいくつかの解決策を見つけました:
- 目的の結果をファイルに書き込み、
doctest
結果とファイルの内容を比較します。 - 結果のハッシュを既知のハッシュと比較します。このアプローチの主な欠点は、 の読者が
doctest
目的の結果についてほとんど学習しないことです。 - doctest を複数行の結果で動作させる方法を見つけてください。
unittest
の代わりに使用しdoctest
ます。
何か案は?
コード:
>>> data_lists=[ {"Average execution" : [1, 2, 3, 2, 3]},
... {"Top execution" : [3, 4, 5, 7, 8, 11, 6]},
... {"Current execution" : [1, 2, 1, 2, 1, 5]} ]
>>> c=Chart(data_lists,
... ("Large<br>rooster", "Rsync rooster", "Pool<br>Chicken", "Disease"),
... width=700, height=300)
>>> print c.html.strip()
<div id="placeholder3" style="width:700px;height:300px"></div>
<script id="source" language="javascript" type="text/javascript">
$(function () {
var d0 = [[0, 1], [4, 2], [8, 3], [12, 2], [16, 3]];
var d1 = [[1, 3], [5, 4], [9, 5], [13, 7], [17, 8], [21, 11], [25, 6]];
var d2 = [[2, 1], [6, 2], [10, 1], [14, 2], [18, 1], [22, 5]];
$.plot($("#placeholder3"), [
{ label: "Average execution", data: d0, bars: { show: true } },
{ label: "Top execution", data: d1, bars: { show: true } },
{ label: "Current execution", data: d2, bars: { show: true } }
],
{
xaxis: { ticks: [[1.5, "Large<br>rooster"], [5.5, "Rsync<br>rooster"], [9.5, "Pool<br>Chicken"], [13.5, "Disease"]] }
}
);
});
</script>
エラー:
**********************************************************************
File "HTML.py", line 28, in __main__.Chart.__init__
Failed example:
print c.html.strip()
Expected:
<div id="placeholder3" style="width:700px;height:300px"></div>
Got:
<div id="placeholder3" style="width:700px;height:300px"></div>
<BLANKLINE>
<script id="source" language="javascript" type="text/javascript">
$(function () {
<BLANKLINE>
var d0 = [[0, 1], [4, 2], [8, 3], [12, 2], [16, 3]];
var d1 = [[1, 3], [5, 4], [9, 5], [13, 7], [17, 8], [21, 11], [25, 6]];
var d2 = [[2, 1], [6, 2], [10, 1], [14, 2], [18, 1], [22, 5]];
<BLANKLINE>
$.plot($("#placeholder3"), [
<BLANKLINE>
{ label: "Average execution", data: d0, bars: { show: true } },
{ label: "Top execution", data: d1, bars: { show: true } },
{ label: "Current execution", data: d2, bars: { show: true } }
<BLANKLINE>
],
{
xaxis: { ticks: [[1.5, "Large<br>rooster"], [5.5, "Rsync rooster"], [9.5, "Pool<br>Chicken"], [13.5, "Disease"]] }
}
);
});
</script>
**********************************************************************
1 items had failures:
1 of 3 in __main__.Chart.
__init__
***Test Failed*** 1 failures.