<commit_before>#!/usr/bin/env python

import sys
import os
import unittest
import subprocess

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import Xlib.display
import Xlib.error
import Xlib.protocol.display
import Xlib.protocol.event
import Xlib.protocol.rq
import Xlib.xobject.fontable
import Xlib.X


class TestXlibDisplay(unittest.TestCase):
    def setUp(self):
        # Create authority file.
        self.display_num = os.getenv("DISPLAY")
        self.display = Xlib.display.Display(self.display_num)
        self.dummy_str = "qqq"
        self.keysym = 65535

    def test_display_instance(self):
        self.assertTrue(isinstance(self.display, Xlib.display.Display))

    def test_default_display_name(self):
        self.assertEqual(self.display.get_display_name(), self.display_num)

    def test_default_screen_number(self):
        self.assertEqual(self.display.get_default_screen(), 0)

    def test_returns_no_events(self):
        self.assertEqual(self.display.pending_events(), 0)

    def test_pointer_mapping_is_list(self):
        self.assertTrue(isinstance(self.display.get_pointer_mapping(), list))

    def test_set_get_pointer_mapping(self):
        length = len(self.display.get_pointer_mapping())
        self.display.set_pointer_mapping([0] * length)
        self.assertEqual(self.display.get_pointer_mapping(), [0] * length)

    def test_can_close_display(self):
        self.display.close()
        self.assertEqual(str(self.display.display.socket_error), "Display connection closed by client")

    def test_can_close_display_and_check_for_error(self):
        self.display.close()
        self.assertRaises(Xlib.error.ConnectionClosedError, self.display.flush)

    def test_return_fileno(self):
        self.assertTrue(isinstance(self.display.fileno(), int))

    def test_has_no_invalid_extension(self):
        self.assertTrue(~self.display.has_extension(self.dummy_str))

    def test_has_valid_extension(self):
        extensions = self.display.list_extensions()
        if extensions:
            self.assertTrue(~self.display.has_extension(extensions[0]))

    def test_can_create_resource_object(self):
        self.assertTrue(
            isinstance(self.display.create_resource_object("font", 0), Xlib.xobject.fontable.Font))

    def test_get_default_screen_instance(self):
        self.assertTrue(isinstance(self.display.screen(), Xlib.protocol.rq.DictWrapper))

    def test_get_zero_screen_instance(self):
        self.assertTrue(isinstance(self.display.screen(0), Xlib.protocol.rq.DictWrapper))

    def test_default_screen_count(self):<commit_msg>test: fix test_xlib_display messing with pointer mapping<commit_after>#!/usr/bin/env python

import sys
import os
import unittest
import subprocess

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import Xlib.display
import Xlib.error
import Xlib.protocol.display
import Xlib.protocol.event
import Xlib.protocol.rq
import Xlib.xobject.fontable
import Xlib.X


class TestXlibDisplay(unittest.TestCase):
    def setUp(self):
        # Create authority file.
        self.display_num = os.getenv("DISPLAY")
        self.display = Xlib.display.Display(self.display_num)
        self.dummy_str = "qqq"
        self.keysym = 65535

    def test_display_instance(self):
        self.assertTrue(isinstance(self.display, Xlib.display.Display))

    def test_default_display_name(self):
        self.assertEqual(self.display.get_display_name(), self.display_num)

    def test_default_screen_number(self):
        self.assertEqual(self.display.get_default_screen(), 0)

    def test_returns_no_events(self):
        self.assertEqual(self.display.pending_events(), 0)

    def test_pointer_mapping_is_list(self):
        self.assertTrue(isinstance(self.display.get_pointer_mapping(), list))

    def test_set_get_pointer_mapping(self):
        orig_mapping = self.display.get_pointer_mapping()
        length = len(orig_mapping)
        try:
            self.display.set_pointer_mapping([0] * length)
            self.assertEqual(self.display.get_pointer_mapping(), [0] * length)
        finally:
            self.display.set_pointer_mapping(orig_mapping)

    def test_can_close_display(self):
        self.display.close()
        self.assertEqual(str(self.display.display.socket_error), "Display connection closed by client")

    def test_can_close_display_and_check_for_error(self):
        self.display.close()
        self.assertRaises(Xlib.error.ConnectionClosedError, self.display.flush)

    def test_return_fileno(self):
        self.assertTrue(isinstance(self.display.fileno(), int))

    def test_has_no_invalid_extension(self):
        self.assertTrue(~self.display.has_extension(self.dummy_str))

    def test_has_valid_extension(self):
        extensions = self.display.list_extensions()
        if extensions:
            self.assertTrue(~self.display.has_extension(extensions[0]))

    def test_can_create_resource_object(self):
        self.assertTrue(
            isinstance(self.display.create_resource_object("font", 0), Xlib.xobject.fontable.Font))

    def test_get_default_screen_instance(self):
        self.assertTrue(isinstance(self.display.screen(), Xlib.protocol.rq.DictWrapper))

    def test_get_zero_screen_instance(self):
        self.assertTrue(isinstance(self.display.screen(0), Xlib.protocol.rq.DictWrapper))

    def test_default_screen_count(self):
{'fraction_non_alphanumeric': 0.10617832038475768, 'fraction_numerical': 0.004439511653718091, 'mean_word_length': 3.910990009082652, 'pattern_counts': {'":': 0, '<': 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': '6169347', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1634, 'n_words': 236}