Python matplotlib._called_from_pytest() Examples

The following are 23 code examples for showing how to use matplotlib._called_from_pytest(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module matplotlib , or try the search function .

Example 1
Project: GraphicDesignPatternByPython   Author: Relph1119   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_configure(config):
    matplotlib.use('agg', force=True)
    matplotlib._called_from_pytest = True
    matplotlib._init_tests() 
Example 2
Project: GraphicDesignPatternByPython   Author: Relph1119   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_unconfigure(config):
    matplotlib._called_from_pytest = False 
Example 3
Project: GraphicDesignPatternByPython   Author: Relph1119   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_check(objects='mhi', format="pdf", usetex=False):
    """
    Output three times the same graphs and checks that the outputs are exactly
    the same.

    Parameters
    ----------
    objects : str
        contains characters corresponding to objects to be included in the test
        document: 'm' for markers, 'h' for hatch patterns, 'i' for images. The
        default value is "mhi", so that the test includes all these objects.
    format : str
        format string. The default value is "pdf".
    """
    plots = []
    for i in range(3):
        result = subprocess.check_output([
            sys.executable, '-R', '-c',
            'import matplotlib; '
            'matplotlib._called_from_pytest = True; '
            'matplotlib.use(%r); '
            'from matplotlib.testing.determinism import _determinism_save;'
            '_determinism_save(%r, %r, %r)'
            % (format, objects, format, usetex)])
        plots.append(result)
    for p in plots[1:]:
        if usetex:
            if p != plots[0]:
                pytest.skip("failed, maybe due to ghostscript timestamps")
        else:
            assert p == plots[0] 
Example 4
Project: GraphicDesignPatternByPython   Author: Relph1119   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
    """
    Test SOURCE_DATE_EPOCH support. Output a document with the environment
    variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
    document contains the timestamp that corresponds to this date (given as an
    argument).

    Parameters
    ----------
    format : str
        format string, such as "pdf".
    string : str
        timestamp string for 2000-01-01 00:00 UTC.
    keyword : bytes
        a string to look at when searching for the timestamp in the document
        (used in case the test fails).
    """
    buff = subprocess.check_output([
        sys.executable, '-R', '-c',
        'import matplotlib; '
        'matplotlib._called_from_pytest = True; '
        'matplotlib.use(%r); '
        'from matplotlib.testing.determinism import _determinism_save;'
        '_determinism_save(%r, %r)'
        % (format, "", format)])
    find_keyword = re.compile(b".*" + keyword + b".*")
    key = find_keyword.search(buff)
    if key:
        print(key.group())
    else:
        print("Timestamp keyword (%s) not found!" % keyword)
    assert string in buff 
Example 5
Project: python3_ios   Author: holzschu   File: test_backend_svg.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_determinism(filename, usetex):
    import sys
    from subprocess import check_output, STDOUT, CalledProcessError
    plots = []
    for i in range(3):
        # Using check_output and setting stderr to STDOUT will capture the real
        # problem in the output property of the exception
        try:
            check_output(
                [sys.executable, '-R', '-c',
                 'import matplotlib; '
                 'matplotlib._called_from_pytest = True; '
                 'matplotlib.use("svg", force=True); '
                 'from matplotlib.tests.test_backend_svg '
                 'import _test_determinism_save;'
                 '_test_determinism_save(%r, %r)' % (filename, usetex)],
                stderr=STDOUT)
        except CalledProcessError as e:
            # it's easier to use utf8 and ask for forgiveness than try
            # to figure out what the current console has as an
            # encoding :-/
            print(e.output.decode(encoding="utf-8", errors="ignore"))
            raise e
        else:
            with open(filename, 'rb') as fd:
                plots.append(fd.read())
        finally:
            os.unlink(filename)
    for p in plots[1:]:
        assert p == plots[0] 
Example 6
Project: python3_ios   Author: holzschu   File: conftest.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def pytest_configure(config):
    matplotlib.use('agg', force=True)
    matplotlib._called_from_pytest = True
    matplotlib._init_tests() 
Example 7
Project: python3_ios   Author: holzschu   File: conftest.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def pytest_unconfigure(config):
    matplotlib._called_from_pytest = False 
Example 8
Project: python3_ios   Author: holzschu   File: determinism.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _determinism_check(objects='mhi', format="pdf", usetex=False):
    """
    Output three times the same graphs and checks that the outputs are exactly
    the same.

    Parameters
    ----------
    objects : str
        contains characters corresponding to objects to be included in the test
        document: 'm' for markers, 'h' for hatch patterns, 'i' for images. The
        default value is "mhi", so that the test includes all these objects.
    format : str
        format string. The default value is "pdf".
    """
    plots = []
    for i in range(3):
        result = subprocess.check_output([
            sys.executable, '-R', '-c',
            'import matplotlib; '
            'matplotlib._called_from_pytest = True; '
            'matplotlib.use(%r); '
            'from matplotlib.testing.determinism import _determinism_save;'
            '_determinism_save(%r, %r, %r)'
            % (format, objects, format, usetex)])
        plots.append(result)
    for p in plots[1:]:
        if usetex:
            if p != plots[0]:
                pytest.skip("failed, maybe due to ghostscript timestamps")
        else:
            assert p == plots[0] 
Example 9
Project: python3_ios   Author: holzschu   File: determinism.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
    """
    Test SOURCE_DATE_EPOCH support. Output a document with the environment
    variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
    document contains the timestamp that corresponds to this date (given as an
    argument).

    Parameters
    ----------
    format : str
        format string, such as "pdf".
    string : str
        timestamp string for 2000-01-01 00:00 UTC.
    keyword : bytes
        a string to look at when searching for the timestamp in the document
        (used in case the test fails).
    """
    buff = subprocess.check_output([
        sys.executable, '-R', '-c',
        'import matplotlib; '
        'matplotlib._called_from_pytest = True; '
        'matplotlib.use(%r); '
        'from matplotlib.testing.determinism import _determinism_save;'
        '_determinism_save(%r, %r)'
        % (format, "", format)])
    find_keyword = re.compile(b".*" + keyword + b".*")
    key = find_keyword.search(buff)
    if key:
        print(key.group())
    else:
        print("Timestamp keyword (%s) not found!" % keyword)
    assert string in buff 
Example 10
Project: coffeegrindsize   Author: jgagneastro   File: test_backend_svg.py    License: MIT License 5 votes vote down vote up
def test_determinism(filename, usetex):
    import sys
    from subprocess import check_output, STDOUT, CalledProcessError
    plots = []
    for i in range(3):
        # Using check_output and setting stderr to STDOUT will capture the real
        # problem in the output property of the exception
        try:
            check_output(
                [sys.executable, '-R', '-c',
                 'import matplotlib; '
                 'matplotlib._called_from_pytest = True; '
                 'matplotlib.use("svg", force=True); '
                 'from matplotlib.tests.test_backend_svg '
                 'import _test_determinism_save;'
                 '_test_determinism_save(%r, %r)' % (filename, usetex)],
                stderr=STDOUT)
        except CalledProcessError as e:
            # it's easier to use utf8 and ask for forgiveness than try
            # to figure out what the current console has as an
            # encoding :-/
            print(e.output.decode(encoding="utf-8", errors="ignore"))
            raise e
        else:
            with open(filename, 'rb') as fd:
                plots.append(fd.read())
        finally:
            os.unlink(filename)
    for p in plots[1:]:
        assert p == plots[0] 
Example 11
Project: coffeegrindsize   Author: jgagneastro   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_configure(config):
    matplotlib.use('agg', force=True)
    matplotlib._called_from_pytest = True
    matplotlib._init_tests() 
Example 12
Project: coffeegrindsize   Author: jgagneastro   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_unconfigure(config):
    matplotlib._called_from_pytest = False 
Example 13
Project: coffeegrindsize   Author: jgagneastro   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_check(objects='mhi', format="pdf", usetex=False):
    """
    Output three times the same graphs and checks that the outputs are exactly
    the same.

    Parameters
    ----------
    objects : str
        contains characters corresponding to objects to be included in the test
        document: 'm' for markers, 'h' for hatch patterns, 'i' for images. The
        default value is "mhi", so that the test includes all these objects.
    format : str
        format string. The default value is "pdf".
    """
    plots = []
    for i in range(3):
        result = subprocess.check_output([
            sys.executable, '-R', '-c',
            'import matplotlib; '
            'matplotlib._called_from_pytest = True; '
            'matplotlib.use(%r); '
            'from matplotlib.testing.determinism import _determinism_save;'
            '_determinism_save(%r, %r, %r)'
            % (format, objects, format, usetex)])
        plots.append(result)
    for p in plots[1:]:
        if usetex:
            if p != plots[0]:
                pytest.skip("failed, maybe due to ghostscript timestamps")
        else:
            assert p == plots[0] 
Example 14
Project: coffeegrindsize   Author: jgagneastro   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
    """
    Test SOURCE_DATE_EPOCH support. Output a document with the environment
    variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
    document contains the timestamp that corresponds to this date (given as an
    argument).

    Parameters
    ----------
    format : str
        format string, such as "pdf".
    string : str
        timestamp string for 2000-01-01 00:00 UTC.
    keyword : bytes
        a string to look at when searching for the timestamp in the document
        (used in case the test fails).
    """
    buff = subprocess.check_output([
        sys.executable, '-R', '-c',
        'import matplotlib; '
        'matplotlib._called_from_pytest = True; '
        'matplotlib.use(%r); '
        'from matplotlib.testing.determinism import _determinism_save;'
        '_determinism_save(%r, %r)'
        % (format, "", format)])
    find_keyword = re.compile(b".*" + keyword + b".*")
    key = find_keyword.search(buff)
    if key:
        print(key.group())
    else:
        print("Timestamp keyword (%s) not found!" % keyword)
    assert string in buff 
Example 15
Project: CogAlg   Author: boris-kz   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_configure(config):
    matplotlib.use('agg', force=True)
    matplotlib._called_from_pytest = True
    matplotlib._init_tests() 
Example 16
Project: CogAlg   Author: boris-kz   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_unconfigure(config):
    matplotlib._called_from_pytest = False 
Example 17
Project: CogAlg   Author: boris-kz   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_check(objects='mhi', format="pdf", usetex=False):
    """
    Output three times the same graphs and checks that the outputs are exactly
    the same.

    Parameters
    ----------
    objects : str
        contains characters corresponding to objects to be included in the test
        document: 'm' for markers, 'h' for hatch patterns, 'i' for images. The
        default value is "mhi", so that the test includes all these objects.
    format : str
        format string. The default value is "pdf".
    """
    plots = []
    for i in range(3):
        result = subprocess.check_output([
            sys.executable, '-R', '-c',
            'import matplotlib; '
            'matplotlib._called_from_pytest = True; '
            'matplotlib.use(%r); '
            'from matplotlib.testing.determinism import _determinism_save;'
            '_determinism_save(%r, %r, %r)'
            % (format, objects, format, usetex)])
        plots.append(result)
    for p in plots[1:]:
        if usetex:
            if p != plots[0]:
                pytest.skip("failed, maybe due to ghostscript timestamps")
        else:
            assert p == plots[0] 
Example 18
Project: CogAlg   Author: boris-kz   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
    """
    Test SOURCE_DATE_EPOCH support. Output a document with the environment
    variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
    document contains the timestamp that corresponds to this date (given as an
    argument).

    Parameters
    ----------
    format : str
        format string, such as "pdf".
    string : str
        timestamp string for 2000-01-01 00:00 UTC.
    keyword : bytes
        a string to look at when searching for the timestamp in the document
        (used in case the test fails).
    """
    buff = subprocess.check_output([
        sys.executable, '-R', '-c',
        'import matplotlib; '
        'matplotlib._called_from_pytest = True; '
        'matplotlib.use(%r); '
        'from matplotlib.testing.determinism import _determinism_save;'
        '_determinism_save(%r, %r)'
        % (format, "", format)])
    find_keyword = re.compile(b".*" + keyword + b".*")
    key = find_keyword.search(buff)
    if key:
        print(key.group())
    else:
        print("Timestamp keyword (%s) not found!" % keyword)
    assert string in buff 
Example 19
Project: twitter-stock-recommendation   Author: alvarobartt   File: test_backend_svg.py    License: MIT License 5 votes vote down vote up
def test_determinism(filename, usetex):
    import sys
    from subprocess import check_output, STDOUT, CalledProcessError
    plots = []
    for i in range(3):
        # Using check_output and setting stderr to STDOUT will capture the real
        # problem in the output property of the exception
        try:
            check_output(
                [sys.executable, '-R', '-c',
                 'import matplotlib; '
                 'matplotlib._called_from_pytest = True; '
                 'matplotlib.use("svg"); '
                 'from matplotlib.tests.test_backend_svg '
                 'import _test_determinism_save;'
                 '_test_determinism_save(%r, %r)' % (filename, usetex)],
                stderr=STDOUT)
        except CalledProcessError as e:
            # it's easier to use utf8 and ask for forgiveness than try
            # to figure out what the current console has as an
            # encoding :-/
            print(e.output.decode(encoding="utf-8", errors="ignore"))
            raise e
        else:
            with open(filename, 'rb') as fd:
                plots.append(fd.read())
        finally:
            os.unlink(filename)
    for p in plots[1:]:
        assert p == plots[0] 
Example 20
Project: twitter-stock-recommendation   Author: alvarobartt   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_configure(config):
    matplotlib.use('agg')
    matplotlib._called_from_pytest = True
    matplotlib._init_tests() 
Example 21
Project: twitter-stock-recommendation   Author: alvarobartt   File: conftest.py    License: MIT License 5 votes vote down vote up
def pytest_unconfigure(config):
    matplotlib._called_from_pytest = False 
Example 22
Project: twitter-stock-recommendation   Author: alvarobartt   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_check(objects='mhi', format="pdf", usetex=False):
    """
    Output three times the same graphs and checks that the outputs are exactly
    the same.

    Parameters
    ----------
    objects : str
        contains characters corresponding to objects to be included in the test
        document: 'm' for markers, 'h' for hatch patterns, 'i' for images. The
        default value is "mhi", so that the test includes all these objects.
    format : str
        format string. The default value is "pdf".
    """
    plots = []
    for i in range(3):
        result = check_output([sys.executable, '-R', '-c',
                               'import matplotlib; '
                               'matplotlib._called_from_pytest = True; '
                               'matplotlib.use(%r); '
                               'from matplotlib.testing.determinism '
                               'import _determinism_save;'
                               '_determinism_save(%r,%r,%r)'
                               % (format, objects, format, usetex)])
        plots.append(result)
    for p in plots[1:]:
        if usetex:
            if p != plots[0]:
                pytest.skip("failed, maybe due to ghostscript timestamps")
        else:
            assert p == plots[0] 
Example 23
Project: twitter-stock-recommendation   Author: alvarobartt   File: determinism.py    License: MIT License 5 votes vote down vote up
def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"):
    """
    Test SOURCE_DATE_EPOCH support. Output a document with the environment
    variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
    document contains the timestamp that corresponds to this date (given as an
    argument).

    Parameters
    ----------
    format : str
        format string, such as "pdf".
    string : str
        timestamp string for 2000-01-01 00:00 UTC.
    keyword : bytes
        a string to look at when searching for the timestamp in the document
        (used in case the test fails).
    """
    buff = check_output([sys.executable, '-R', '-c',
                         'import matplotlib; '
                         'matplotlib._called_from_pytest = True; '
                         'matplotlib.use(%r); '
                         'from matplotlib.testing.determinism '
                         'import _determinism_save;'
                         '_determinism_save(%r,%r)'
                         % (format, "", format)])
    find_keyword = re.compile(b".*" + keyword + b".*")
    key = find_keyword.search(buff)
    if key:
        print(key.group())
    else:
        print("Timestamp keyword (%s) not found!" % keyword)
    assert string in buff