<commit_before># Copyright 2012 the rootpy developers
# distributed under the terms of the GNU General Public License
from rootpy.plotting import Hist, Hist2D, Graph
from nose.plugins.skip import SkipTest


def test_errorbar():
    try:
        from rootpy.plotting import root2matplotlib as rplt
    except ImportError:
        raise SkipTest
    h = Hist(100, -5, 5)
    h.FillRandom('gaus')
    g = Graph(h)
    rplt.errorbar(g)
    rplt.errorbar(h)


def test_bar():
    try:
        from rootpy.plotting import root2matplotlib as rplt
    except ImportError:
        raise SkipTest
    h = Hist(100, -5, 5)
    h.FillRandom('gaus')
    rplt.bar(h)


def test_hist():
    try:
        from rootpy.plotting import root2matplotlib as rplt
    except ImportError:
        raise SkipTest
    h = Hist(100, -5, 5)
    h.FillRandom('gaus')
    rplt.hist(h)


def test_hist2d():
    try:
        from rootpy.plotting import root2matplotlib as rplt
        from matplotlib import pyplot
        import numpy as np
    except ImportError:
        raise SkipTest
    if not hasattr(pyplot, 'hist2d'):
        raise SkipTest
    a = Hist2D(100, -3, 3, 100, 0, 6)
    a.fill_array(np.random.multivariate_normal(
        mean=(0, 3),
        cov=np.arange(4).reshape(2, 2),
        size=(1E3,)))
    rplt.hist2d(a)


def test_imshow():
    try:
        from rootpy.plotting import root2matplotlib as rplt
        import numpy as np
    except ImportError:
        raise SkipTest
    a = Hist2D(100, -3, 3, 100, 0, 6)
    a.fill_array(np.random.multivariate_normal(
        mean=(0, 3),
        cov=np.arange(4).reshape(2, 2),
        size=(1E3,)))
    rplt.imshow(a)


def test_contour():
    try:
        from rootpy.plotting import root2matplotlib as rplt
        import numpy as np
    except ImportError:
        raise SkipTest
    a = Hist2D(100, -3, 3, 100, 0, 6)
    a.fill_array(np.random.multivariate_normal(
        mean=(0, 3),
        cov=np.arange(4).reshape(2, 2),
        size=(1E3,)))
    rplt.contour(a)


if __name__ == "__main__":
    import nose
    nose.runmodule()<commit_msg>root2matplotlib: fix backend in unit tests<commit_after># Copyright 2012 the rootpy developers
# distributed under the terms of the GNU General Public License
from rootpy.plotting import Hist, Hist2D, Graph
from nose.plugins.skip import SkipTest
from nose.tools import with_setup


def setup_func():
    try:
        import matplotlib
    except ImportError:
        raise SkipTest("matplotlib is not importable")
    matplotlib.use('Agg')
    from matplotlib import pyplot
    pyplot.ioff()


@with_setup(setup_func)
def test_errorbar():
    from rootpy.plotting import root2matplotlib as rplt
    h = Hist(100, -5, 5)
    h.FillRandom('gaus')
    g = Graph(h)
    rplt.errorbar(g)
    rplt.errorbar(h)


@with_setup(setup_func)
def test_bar():
    from rootpy.plotting import root2matplotlib as rplt
    h = Hist(100, -5, 5)
    h.FillRandom('gaus')
    rplt.bar(h)


@with_setup(setup_func)
def test_hist():
    from rootpy.plotting import root2matplotlib as rplt
    h = Hist(100, -5, 5)
    h.FillRandom('gaus')
    rplt.hist(h)


@with_setup(setup_func)
def test_hist2d():
    from rootpy.plotting import root2matplotlib as rplt
    from matplotlib import pyplot
    import numpy as np
    if not hasattr(pyplot, 'hist2d'):
        raise SkipTest("matplotlib is too old")
    a = Hist2D(100, -3, 3, 100, 0, 6)
    a.fill_array(np.random.multivariate_normal(
        mean=(0, 3),
        cov=np.arange(4).reshape(2, 2),
        size=(1E3,)))
    rplt.hist2d(a)


@with_setup(setup_func)
def test_imshow():
    from rootpy.plotting import root2matplotlib as rplt
    import numpy as np
    a = Hist2D(100, -3, 3, 100, 0, 6)
    a.fill_array(np.random.multivariate_normal(
        mean=(0, 3),
        cov=np.arange(4).reshape(2, 2),
        size=(1E3,)))
    rplt.imshow(a)


@with_setup(setup_func)
def test_contour():
    from rootpy.plotting import root2matplotlib as rplt
    import numpy as np
    a = Hist2D(100, -3, 3, 100, 0, 6)
    a.fill_array(np.random.multivariate_normal(
        mean=(0, 3),
        cov=np.arange(4).reshape(2, 2),
        size=(1E3,)))
    rplt.contour(a)


if __name__ == "__main__":
    import nose
    nose.runmodule()
{'fraction_non_alphanumeric': 0.10998586905322656, 'fraction_numerical': 0.039331135186057464, 'mean_word_length': 2.7784697508896796, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6806594', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1513, 'n_words': 395}