<commit_before>from __future__ import absolute_import

import plotly.tools as tls
import imghdr
import threading


def test_plotly_display():
    plot_info = {"un": "plotlyimagetest", "fid": "2"}
    url = "https://plot.ly/~{un}/{fid}".format(**plot_info)
    disp_obj = tls.embed(url)
    format_to_func = {
        "jpeg": jpeg_worker,
        "png": png_worker,
        "svg": svg_worker,
        "pdf": pdf_worker
    }
    results = {}
    threads = []
    for f_format, func in format_to_func.items():
        threads += [threading.Thread(target=func, args=(disp_obj, results))]
        threads[-1].setDaemon(True)
        threads[-1].start()
    for thread in threads:
        thread.join()
    for f_format in format_to_func:
        result = results.get(f_format, False)
        print("{f_format}: {result}".format(f_format=f_format, result=result))
        assert results.get(f_format)


def jpeg_worker(display_obj, results):
    img = display_obj._repr_jpeg_()
    if imghdr.what('', img) == "jpeg":
        results["jpeg"] = True


def png_worker(display_obj, results):
    img = display_obj._repr_png_()
    if imghdr.what('', img) == "png":
        results["png"] = True


def svg_worker(display_obj, results):
    img = display_obj._repr_svg_()
    if img[:4] == '<svg':
        results["svg"] = True


def pdf_worker(display_obj, results):
    img = display_obj._repr_pdf_()
    if img[:4] == '%PDF':
        results["pdf"] = True<commit_msg>trying to use more standard testing formats.<commit_after>from __future__ import absolute_import

import plotly.tools as tls
import imghdr
import threading
import unittest


class TestPlotlyDisplay(unittest.TestCase):

    def setUp(self):
        plot_info = {"un": "plotlyimagetest", "fid": "2"}
        url = "https://plot.ly/~{un}/{fid}".format(**plot_info)
        self.display_obj = tls.embed(url)
        self.results = {}
        self.threads = []
        self.format_to_func = {
            "jpeg": self.jpeg_worker,
            "png": self.png_worker,
            "svg": self.svg_worker,
            "pdf": self.pdf_worker}

    def test_plotly_display(self):
        for f_format, func in self.format_to_func.items():
            self.threads += [threading.Thread(target=func)]
            self.threads[-1].setDaemon(True)
            self.threads[-1].start()
        for thread in self.threads:
            thread.join()
        for f_format in self.format_to_func:
            result = self.results.get(f_format, False)
            print("{f_format}: {result}".format(f_format=f_format,
                                                result=result))
            assert self.results.get(f_format)

    def jpeg_worker(self):
        img = self.display_obj._repr_jpeg_()
        if imghdr.what('', img) == "jpeg":
            self.results["jpeg"] = True

    def png_worker(self):
        img = self.display_obj._repr_png_()
        if imghdr.what('', img) == "png":
            self.results["png"] = True

    def svg_worker(self):
        img = self.display_obj._repr_svg_()
        if img[:4] == '<svg':
            self.results["svg"] = True

    def pdf_worker(self):
        img = self.display_obj._repr_pdf_()
        if img[:4] == '%PDF':
            self.results["pdf"] = True
{'fraction_non_alphanumeric': 0.14097051597051596, 'fraction_numerical': 0.003071253071253071, 'mean_word_length': 2.487152034261242, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6811461', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1048, 'n_words': 213}