def test_warn_error_for_type(): f = HTMLFormatter() f.for_type(int, lambda i: name_error) with capture_output() as captured: result = f(5) nt.assert_is(result, None) nt.assert_in("Traceback", captured.stdout) nt.assert_in("NameError", captured.stdout) nt.assert_in("name_error", captured.stdout)
def test_warn_error_for_type(): f = HTMLFormatter() f.for_type(int, lambda i: name_error) with capture_output() as captured: result = f(5) nt.assert_is(result, None) nt.assert_in("FormatterWarning", captured.stderr) nt.assert_in("text/html", captured.stderr) nt.assert_in("name_error", captured.stderr)
def test_warn_error_for_type(): f = HTMLFormatter() f.for_type(int, lambda i: name_error) with capture_output() as captured: result = f(5) nt.assert_is(result, None) nt.assert_in("Traceback", captured.stdout) nt.assert_in("NameError", captured.stdout) nt.assert_in("name_error", captured.stdout)
def test_warn_error_for_type(): f = HTMLFormatter() f.for_type(int, lambda i: name_error) with capture_output() as captured: result = f(5) assert result is None assert "Traceback" in captured.stdout assert "NameError" in captured.stdout assert "name_error" in captured.stdout
def test_warn_error_for_type(): f = HTMLFormatter() f.for_type(int, lambda i: name_error) with capture_output() as captured: result = f(5) nt.assert_is(result, None) nt.assert_in("WARNING", captured.stderr) nt.assert_in("text/html", captured.stderr) nt.assert_in("name_error", captured.stderr)
def test_print_method_weird(): class TextMagicHat(object): def __getattr__(self, key): return key f = HTMLFormatter() text_hat = TextMagicHat() nt.assert_equal(text_hat._repr_html_, '_repr_html_') with capture_output() as captured: result = f(text_hat) nt.assert_is(result, None) nt.assert_not_in("FormatterWarning", captured.stderr) class CallableMagicHat(object): def __getattr__(self, key): return lambda: key call_hat = CallableMagicHat() with capture_output() as captured: result = f(call_hat) nt.assert_equal(result, None) class BadReprArgs(object): def _repr_html_(self, extra, args): return "html" bad = BadReprArgs() with capture_output() as captured: result = f(bad) nt.assert_is(result, None) nt.assert_not_in("FormatterWarning", captured.stderr)
def test_print_method_weird(): class TextMagicHat(object): def __getattr__(self, key): return key f = HTMLFormatter() text_hat = TextMagicHat() assert text_hat._repr_html_ == "_repr_html_" with capture_output() as captured: result = f(text_hat) assert result is None assert "FormatterWarning" not in captured.stderr class CallableMagicHat(object): def __getattr__(self, key): return lambda: key call_hat = CallableMagicHat() with capture_output() as captured: result = f(call_hat) assert result is None class BadReprArgs(object): def _repr_html_(self, extra, args): return "html" bad = BadReprArgs() with capture_output() as captured: result = f(bad) assert result is None assert "FormatterWarning" not in captured.stderr
def test_nowarn_notimplemented(): f = HTMLFormatter() class HTMLNotImplemented(object): def _repr_html_(self): raise NotImplementedError h = HTMLNotImplemented() with capture_output() as captured: result = f(h) nt.assert_is(result, None) nt.assert_equal("", captured.stderr) nt.assert_equal("", captured.stdout)
def test_warn_error_method(): f = HTMLFormatter() class BadHTML(object): def _repr_html_(self): return 1/0 bad = BadHTML() with capture_output() as captured: result = f(bad) nt.assert_is(result, None) nt.assert_in("WARNING", captured.stderr) nt.assert_in("text/html", captured.stderr) nt.assert_in("zero", captured.stderr)
def test_error_method(): f = HTMLFormatter() class BadHTML(object): def _repr_html_(self): raise ValueError("Bad HTML") bad = BadHTML() with capture_output() as captured: result = f(bad) nt.assert_is(result, None) nt.assert_in("Traceback", captured.stdout) nt.assert_in("Bad HTML", captured.stdout) nt.assert_in("_repr_html_", captured.stdout)
def test_format_config(): """config objects don't pretend to support fancy reprs with lazy attrs""" f = HTMLFormatter() cfg = Config() with capture_output() as captured: result = f(cfg) nt.assert_is(result, None) nt.assert_equal(captured.stderr, "") with capture_output() as captured: result = f(Config) nt.assert_is(result, None) nt.assert_equal(captured.stderr, "")
def test_format_config(): """config objects don't pretend to support fancy reprs with lazy attrs""" f = HTMLFormatter() cfg = Config() with capture_output() as captured: result = f(cfg) assert result is None assert captured.stderr == "" with capture_output() as captured: result = f(Config) assert result is None assert captured.stderr == ""
def test_nowarn_notimplemented(): f = HTMLFormatter() class HTMLNotImplemented(object): def _repr_html_(self): raise NotImplementedError h = HTMLNotImplemented() with capture_output() as captured: result = f(h) assert result is None assert "" == captured.stderr assert "" == captured.stdout
def test_error_method(): f = HTMLFormatter() class BadHTML(object): def _repr_html_(self): raise ValueError("Bad HTML") bad = BadHTML() with capture_output() as captured: result = f(bad) assert result is None assert "Traceback" in captured.stdout assert "Bad HTML" in captured.stdout assert "_repr_html_" in captured.stdout
def test_print_method_bound(): f = HTMLFormatter() class MyHTML(object): def _repr_html_(self): return "hello" with capture_output() as captured: result = f(MyHTML) nt.assert_is(result, None) nt.assert_not_in("FormatterWarning", captured.stderr) with capture_output() as captured: result = f(MyHTML()) nt.assert_equal(result, "hello") nt.assert_equal(captured.stderr, "")
def test_print_method_bound(): f = HTMLFormatter() class MyHTML(object): def _repr_html_(self): return "hello" with capture_output() as captured: result = f(MyHTML) assert result is None assert "FormatterWarning" not in captured.stderr with capture_output() as captured: result = f(MyHTML()) assert result == "hello" assert captured.stderr == ""