Пример #1
0
def test_list():
    list_ = fmtxt.List("Head")
    eq_(html(list_), u'Head\n<ul>\n</ul>')
    list_.add_item("child")
    eq_(html(list_), u'Head\n<ul>\n<li>child</li>\n</ul>')
    sublist = list_.add_sublist(u"unicode:")
    eq_(html(list_), u'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n'
                     u'</ul></li>\n</ul>')
    sublist.add_item(u'delta: ∂')
    eq_(html(list_), u'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n'
                     u'<li>delta: &#8706;</li>\n</ul></li>\n</ul>')
Пример #2
0
def test_fmtext():
    "Tet FMText base class"
    t = fmtxt.FMText('test')
    print t

    tuc = fmtxt.FMText(u'FMText with unicode: \x80abc')
    print str(tuc)

    ts = fmtxt.FMText((t, tuc, u'unicode: \x80abc'))

    print str(ts)
    print html(ts)
    print tex(ts)
Пример #3
0
def test_fmtext():
    "Tet FMText base class"
    t = fmtxt.FMText('test')
    print t

    tuc = fmtxt.FMText(u'FMText with unicode: \x80abc')
    print str(tuc)

    ts = fmtxt.FMText((t, tuc, u'unicode: \x80abc'))

    print str(ts)
    print html(ts)
    print tex(ts)
Пример #4
0
def test_list():
    list_ = fmtxt.List("Head")
    eq_(str(list_), 'Head')
    eq_(html(list_), 'Head\n<ul>\n</ul>')
    list_.add_item("child")
    eq_(str(list_), 'Head\n- child')
    eq_(html(list_), 'Head\n<ul>\n<li>child</li>\n</ul>')
    sublist = list_.add_sublist("unicode:")
    eq_(str(list_), 'Head\n- child\n- unicode:')
    eq_(html(list_), 'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n'
                     '</ul></li>\n</ul>')
    sublist.add_item('delta: ∂')
    eq_(str(list_), 'Head\n- child\n- unicode:\n  - delta: ∂')
    eq_(html(list_), 'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n'
                     '<li>delta: ∂</li>\n</ul></li>\n</ul>')
Пример #5
0
def test_list():
    list_ = fmtxt.List("Head")
    eq_(str(list_), 'Head')
    eq_(html(list_), 'Head\n<ul>\n</ul>')
    list_.add_item("child")
    eq_(str(list_), 'Head\n- child')
    eq_(html(list_), 'Head\n<ul>\n<li>child</li>\n</ul>')
    sublist = list_.add_sublist("unicode:")
    eq_(str(list_), 'Head\n- child\n- unicode:')
    eq_(html(list_), 'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n'
        '</ul></li>\n</ul>')
    sublist.add_item('delta: ∂')
    eq_(str(list_), 'Head\n- child\n- unicode:\n  - delta: ∂')
    eq_(
        html(list_), 'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n'
        '<li>delta: ∂</li>\n</ul></li>\n</ul>')
Пример #6
0
def test_list():
    list_ = fmtxt.List("Head")
    assert str(list_) == 'Head'
    assert html(list_) == 'Head\n<ul>\n</ul>'
    list_.add_item("child")
    assert str(list_) == 'Head\n- child'
    assert html(list_) == 'Head\n<ul>\n<li>child</li>\n</ul>'
    sublist = list_.add_sublist("unicode:")
    assert str(list_) == 'Head\n- child\n- unicode:'
    assert html(
        list_
    ) == 'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n</ul></li>\n</ul>'
    sublist.add_item('delta: ∂')
    assert str(list_) == 'Head\n- child\n- unicode:\n  - delta: ∂'
    assert html(
        list_
    ) == 'Head\n<ul>\n<li>child</li>\n<li>unicode:\n<ul>\n<li>delta: ∂</li>\n</ul></li>\n</ul>'
Пример #7
0
def test_eq():
    "Test equation factory"
    s = fmtxt.eq('t', 0.1234)
    eq_(str(s), "t = 0.12")
    eq_(html(s), "t = 0.12")
    eq_(tex(s), "$t = 0.12$")

    s = fmtxt.eq('t', 0.1234, 18)
    eq_(str(s), "t(18) = 0.12")
    eq_(html(s), "t<sub>18</sub> = 0.12")
    eq_(tex(s), "$t_{18} = 0.12$")

    s = fmtxt.peq(0.1299)
    eq_(str(s), "p = .130")
    eq_(html(s), "p = .130")
    eq_(tex(s), "$p = .130$")

    s = fmtxt.peq(0.0009)
    eq_(str(s), "p < .001")
    eq_(html(s), "p < .001")
    eq_(tex(s), "$p < .001$")
Пример #8
0
def test_eq():
    "Test equation factory"
    s = fmtxt.eq('t', 0.1234)
    assert str(s) == "t = 0.12"
    assert html(s) == "t = 0.12"
    assert tex(s) == "$t = 0.12$"

    s = fmtxt.eq('t', 0.1234, 18)
    assert str(s) == "t(18) = 0.12"
    assert html(s) == "t<sub>18</sub> = 0.12"
    assert tex(s) == "$t_{18} = 0.12$"

    s = fmtxt.peq(0.1299)
    assert str(s) == "p = .130"
    assert html(s) == "p = .130"
    assert tex(s) == "$p = .130$"

    s = fmtxt.peq(0.0009)
    assert str(s) == "p < .001"
    assert html(s) == "p &lt; .001"
    assert tex(s) == "$p < .001$"
Пример #9
0
def test_eq():
    "Test equation factory"
    s = fmtxt.eq('t', 0.1234)
    eq_(str(s), "t = 0.12")
    eq_(html(s), "t = 0.12")
    eq_(tex(s), "$t = 0.12$")

    s = fmtxt.eq('t', 0.1234, 18)
    eq_(str(s), "t(18) = 0.12")
    eq_(html(s), "t<sub>18</sub> = 0.12")
    eq_(tex(s), "$t_{18} = 0.12$")

    s = fmtxt.peq(0.1299)
    eq_(str(s), "p = .130")
    eq_(html(s), "p = .130")
    eq_(tex(s), "$p = .130$")

    s = fmtxt.peq(0.0009)
    eq_(str(s), "p < .001")
    eq_(html(s), "p &lt; .001")
    eq_(tex(s), "$p < .001$")
Пример #10
0
def test_fmtext():
    "Tet FMText base class"
    t = fmtxt.FMText('test')
    print(t)

    tuc = fmtxt.FMText('FMText with unicode: \x80abc')
    print(str(tuc))

    ts = fmtxt.FMText((t, tuc, 'unicode: \x80abc'))

    print(str(ts))
    print(html(ts))
    print(tex(ts))
Пример #11
0
def test_fmtext():
    "Tet FMText base class"
    t = fmtxt.FMText('test')
    print(t)

    tuc = fmtxt.FMText('FMText with unicode: \x80abc')
    print(str(tuc))

    ts = fmtxt.FMText((t, tuc, 'unicode: \x80abc'))

    print(str(ts))
    print(html(ts))
    print(tex(ts))
Пример #12
0
def test_result_report():
    "Test result_report function for different Results"
    ds = datasets.get_uts(True)
    sds = ds.sub("B == 'b0'")

    for y in (
            'uts',  # time
            "utsnd.summary(time=(0.25, 0.35))",  # sensor
            'utsnd',  # sensor x time
    ):
        dims = tuple(dim.name for dim in ds.eval(y).dims[1:])
        logging.info("y=%s %s", y, dims)
        kwargs = dict(pmin=0.1, samples=100)
        if 'time' in dims:
            kwargs['tstart'] = 0.2
            kwargs['tstop'] = 0.4

        for match in (None, 'rm'):
            logging.info("    match=%s", match)
            res = testnd.ttest_1samp(y, match=match, ds=sds, **kwargs)
            rep = result_report(res, ds)
            html(rep)

        res = testnd.ttest_ind(y, 'A', ds=sds, **kwargs)
        rep = result_report(res, ds)
        html(rep)

        res = testnd.ttest_rel(y, 'A', ds=sds, match='rm', **kwargs)
        rep = result_report(res, sds)
        html(rep)

        res = testnd.anova(y, 'A * B', ds=ds, **kwargs)
        rep = result_report(res, ds)
        html(rep)

        res = testnd.anova(y, 'A * rm', ds=sds, match='rm', **kwargs)
        rep = result_report(res, ds)
        html(rep)
Пример #13
0
def test_result_report():
    "Test result_report function for different Results"
    ds = datasets.get_uts(True)
    sds = ds.sub("B == 'b0'")
    ys = [
        'uts',  # time
        "utsnd.summary(time=(0.25, 0.35))",  # sensor
        'utsnd',  # sensor x time
    ]

    for y in ys:
        y_obj = sds.eval(y)
        kwargs = dict(pmin=0.1, samples=100)
        if y_obj.has_dim('time'):
            kwargs['tstart'] = 0.2
            kwargs['tstop'] = 0.4

        for match in (None, 'rm'):
            logging.info("    match=%s", match)
            res = testnd.ttest_1samp(y, match=match, ds=sds, **kwargs)
            rep = result_report(res, ds)
            html(rep)

        res = testnd.ttest_ind(y, 'A', ds=sds, **kwargs)
        rep = result_report(res, ds)
        html(rep)

        res = testnd.ttest_rel(y, 'A', ds=sds, match='rm', **kwargs)
        rep = result_report(res, sds)
        html(rep)

        res = testnd.anova(y, 'A * B', ds=ds, **kwargs)
        rep = result_report(res, ds)
        html(rep)

        res = testnd.anova(y, 'A * rm', ds=sds, match='rm', **kwargs)
        rep = result_report(res, ds)
        html(rep)
Пример #14
0
def test_result_report():
    "Test result_report function for different Results"
    ds = datasets.get_uts(True)
    sds = ds.sub("B == 'b0'")

    for y in ('uts',  # time
              "utsnd.summary(time=(0.25, 0.35))",  # sensor
              'utsnd',  # sensor x time
              ):
        dims = tuple(dim.name for dim in ds.eval(y).dims[1:])
        logging.info("y=%s %s", y, dims)
        kwargs = dict(pmin=0.1, samples=100)
        if 'time' in dims:
            kwargs['tstart'] = 0.2
            kwargs['tstop'] = 0.4

        for match in (None, 'rm'):
            logging.info("    match=%s", match)
            res = testnd.ttest_1samp(y, match=match, ds=sds, **kwargs)
            rep = result_report(res, ds)
            html(rep)

        res = testnd.ttest_ind(y, 'A', ds=sds, **kwargs)
        rep = result_report(res, ds)
        html(rep)

        res = testnd.ttest_rel(y, 'A',  ds=sds, match='rm', **kwargs)
        rep = result_report(res, sds)
        html(rep)

        res = testnd.anova(y, 'A * B', ds=ds, **kwargs)
        rep = result_report(res, ds)
        html(rep)

        res = testnd.anova(y, 'A * rm', ds=sds, match='rm', **kwargs)
        rep = result_report(res, ds)
        html(rep)
Пример #15
0
def test_table():
    table = fmtxt.Table('ll')
    table.cells('A', 'B')
    table.midrule()
    table.cells('a1', 'b1', 'a2', 'b2')
    assert str(table) == 'A    B \n-------\na1   b1\na2   b2'
    assert html(table) == (
        '<figure><table border="1" cellpadding="2" frame="hsides" rules="none"><tr>\n'
        ' <td>A</td>\n <td>B</td>\n</tr>\n<tr>\n'
        ' <td>a1</td>\n <td>b1</td>\n</tr>\n<tr>\n'
        ' <td>a2</td>\n <td>b2</td>\n</tr></table></figure>')
    assert table.get_rtf() == ('\\trowd\n\\cellx0000\n\\cellx1000\n\\row\n'
                               'A\\intbl\\cell\nB\\intbl\\cell\n\\row\n'
                               'a1\\intbl\\cell\nb1\\intbl\\cell\n\\row\n'
                               'a2\\intbl\\cell\nb2\\intbl\\cell\n\\row')
    assert table.get_tex() == (
        '\\begin{center}\n\\begin{tabular}{ll}\n\\toprule\n'
        'A & B \\\\\n\\midrule\n'
        'a1 & b1 \\\\\na2 & b2 \\\\\n'
        '\\bottomrule\n\\end{tabular}\n\\end{center}')

    # empty table
    str(fmtxt.Table(''))

    # saving
    tempdir = TempDir()
    # HTML
    path = os.path.join(tempdir, 'test.html')
    table.save_html(path)
    assert open(path).read() == (
        '<!DOCTYPE html>\n<html>\n<head>\n'
        '    <title>Untitled</title>\n'
        '<style>\n\n.float {\n    float:left\n}\n\n'
        '</style>\n</head>\n\n'
        '<body>\n\n<figure>'
        '<table border="1" cellpadding="2" frame="hsides" rules="none"><tr>\n'
        ' <td>A</td>\n <td>B</td>\n</tr>\n<tr>\n'
        ' <td>a1</td>\n <td>b1</td>\n</tr>\n<tr>\n'
        ' <td>a2</td>\n <td>b2</td>\n</tr>'
        '</table></figure>\n\n</body>\n</html>\n')
    # rtf
    path = os.path.join(tempdir, 'test.rtf')
    table.save_rtf(path)
    assert open(path).read() == ('{\\rtf1\\ansi\\deff0\n\n'
                                 '\\trowd\n\\cellx0000\n\\cellx1000\n\\row\n'
                                 'A\\intbl\\cell\nB\\intbl\\cell\n\\row\n'
                                 'a1\\intbl\\cell\nb1\\intbl\\cell\n\\row\n'
                                 'a2\\intbl\\cell\nb2\\intbl\\cell\n\\row\n}')
    # TeX
    path = os.path.join(tempdir, 'test.tex')
    table.save_tex(path)
    assert open(path).read() == (
        '\\begin{center}\n\\begin{tabular}{ll}\n\\toprule\n'
        'A & B \\\\\n\\midrule\n'
        'a1 & b1 \\\\\na2 & b2 \\\\\n'
        '\\bottomrule\n\\end{tabular}\n\\end{center}')
    # txt
    path = os.path.join(tempdir, 'test.txt')
    table.save_txt(path)
    assert open(path).read() == 'A    B \n-------\na1   b1\na2   b2'

    # editing
    table[0, 0] = 'X'
    assert str(table) == 'X    B \n-------\na1   b1\na2   b2'
    table[0] = ['C', 'D']
    assert str(table) == 'C    D \n-------\na1   b1\na2   b2'
    table[2, 0] = 'cd'
    assert str(table) == 'C    D \n-------\ncd   b1\na2   b2'
    table[2:4, 1] = ['x', 'y']
    assert str(table) == 'C    D\n------\ncd   x\na2   y'
Пример #16
0
def test_code():
    "test fmtxt.Code"
    eq_(html(fmtxt.Code("a = 5\nb = a + 2")),
        "<code>a{s}={s}5{br}b{s}={s}a{s}+{s}2</code>".
        format(s='&nbsp;', br='<br style="clear:left">\n'))
Пример #17
0
def test_symbol():
    "Test fmtxt.symbol()"
    s = fmtxt.symbol('t', 21)
    eq_(str(s), 't(21)')
    eq_(html(s), 't<sub>21</sub>')
    eq_(tex(s), '$t_{21}$')
Пример #18
0
def test_code():
    "test fmtxt.Code"
    eq_(html(fmtxt.Code("a = 5\nb = a + 2")),
        "<code>a{s}={s}5{br}b{s}={s}a{s}+{s}2</code>".
        format(s='&nbsp;', br='<br style="clear:left">\n'))
Пример #19
0
def test_symbol():
    "Test fmtxt.symbol()"
    s = fmtxt.symbol('t', 21)
    eq_(str(s), 't(21)')
    eq_(html(s), 't<sub>21</sub>')
    eq_(tex(s), '$t_{21}$')
Пример #20
0
def test_symbol():
    "Test fmtxt.symbol()"
    s = fmtxt.symbol('t', 21)
    assert_equal(str(s), 't(21)')
    assert_equal(html(s), 't<sub>21</sub>')
Пример #21
0
def test_symbol():
    "Test fmtxt.symbol()"
    s = fmtxt.symbol('t', 21)
    assert_equal(str(s), 't(21)')
    assert_equal(html(s), 't<sub>21</sub>')
Пример #22
0
def test_code():
    "test fmtxt.Code"
    s = '&nbsp;'
    br = '<br style="clear:left">\n'
    assert html(fmtxt.Code(
        "a = 5\nb = a + 2")) == f"<code>a{s}={s}5{br}b{s}={s}a{s}+{s}2</code>"
Пример #23
0
def test_table():
    table = fmtxt.Table('ll')
    table.cells('A', 'B')
    table.midrule()
    table.cells('a1', 'b1', 'a2', 'b2')
    eq_(str(table), 'A    B \n-------\na1   b1\na2   b2')
    eq_(html(table), '<figure><table border="1" cellpadding="2" frame="hsides" rules="none"><tr>\n'
                     ' <td>A</td>\n <td>B</td>\n</tr>\n<tr>\n'
                     ' <td>a1</td>\n <td>b1</td>\n</tr>\n<tr>\n'
                     ' <td>a2</td>\n <td>b2</td>\n</tr></table></figure>')
    eq_(table.get_rtf(), '\\trowd\n\\cellx0000\n\\cellx1000\n\\row\n'
                         'A\\intbl\\cell\nB\\intbl\\cell\n\\row\n'
                         'a1\\intbl\\cell\nb1\\intbl\\cell\n\\row\n'
                         'a2\\intbl\\cell\nb2\\intbl\\cell\n\\row')
    eq_(table.get_tex(), '\\begin{center}\n\\begin{tabular}{ll}\n\\toprule\n'
                         'A & B \\\\\n\\midrule\n'
                         'a1 & b1 \\\\\na2 & b2 \\\\\n'
                         '\\bottomrule\n\\end{tabular}\n\\end{center}')

    # empty table
    str(fmtxt.Table(''))

    # saving
    tempdir = TempDir()
    # HTML
    path = os.path.join(tempdir, 'test.html')
    table.save_html(path)
    eq_(open(path).read(),  '<!DOCTYPE html>\n<html>\n<head>\n'
                            '    <title>Untitled</title>\n'
                            '<style>\n\n.float {\n    float:left\n}\n\n'
                            '</style>\n</head>\n\n'
                            '<body>\n\n<figure>'
                            '<table border="1" cellpadding="2" frame="hsides" rules="none"><tr>\n'
                            ' <td>A</td>\n <td>B</td>\n</tr>\n<tr>\n'
                            ' <td>a1</td>\n <td>b1</td>\n</tr>\n<tr>\n'
                            ' <td>a2</td>\n <td>b2</td>\n</tr>'
                            '</table></figure>\n\n</body>\n</html>\n')
    # rtf
    path = os.path.join(tempdir, 'test.rtf')
    table.save_rtf(path)
    eq_(open(path).read(), '{\\rtf1\\ansi\\deff0\n\n'
                           '\\trowd\n\\cellx0000\n\\cellx1000\n\\row\n'
                           'A\\intbl\\cell\nB\\intbl\\cell\n\\row\n'
                           'a1\\intbl\\cell\nb1\\intbl\\cell\n\\row\n'
                           'a2\\intbl\\cell\nb2\\intbl\\cell\n\\row\n}')
    # TeX
    path = os.path.join(tempdir, 'test.tex')
    table.save_tex(path)
    eq_(open(path).read(), '\\begin{center}\n\\begin{tabular}{ll}\n\\toprule\n'
                           'A & B \\\\\n\\midrule\n'
                           'a1 & b1 \\\\\na2 & b2 \\\\\n'
                           '\\bottomrule\n\\end{tabular}\n\\end{center}')
    # txt
    path = os.path.join(tempdir, 'test.txt')
    table.save_txt(path)
    eq_(open(path).read(), 'A    B \n-------\na1   b1\na2   b2')

    # editing
    table[0, 0] = 'X'
    eq_(str(table), 'X    B \n-------\na1   b1\na2   b2')
    table[0] = ['C', 'D']
    eq_(str(table), 'C    D \n-------\na1   b1\na2   b2')
    table[2, 0] = 'cd'
    eq_(str(table), 'C    D \n-------\ncd   b1\na2   b2')
    table[2:4, 1] = ['x', 'y']
    eq_(str(table), 'C    D\n------\ncd   x\na2   y')
Пример #24
0
def test_symbol():
    "Test fmtxt.symbol()"
    s = fmtxt.symbol('t', 21)
    assert str(s) == 't(21)'
    assert html(s) == 't<sub>21</sub>'
    assert tex(s) == '$t_{21}$'