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

import subprocess
from subprocess import Popen
import os
from os import listdir, path
from os.path import isfile, join
from shutil import which
import sys
import re
import time

PYTEST = 'py.test-3.5'
XVFB = 'Xvfb'
I3_BINARY = 'i3'
LOCKDIR = '/tmp'

def check_dependencies():
    if not which(XVFB):
        # TODO make this optional
        print('Xvfb is required to run tests')
        print('Command "%s" not found in PATH' % XVFB)
        sys.exit(127)

    if not which(I3_BINARY):
        print('i3 binary is required to run tests')
        print('Command "%s" not found in PATH' % I3_BINARY)
        sys.exit(127)

def get_open_display():
    # TODO find the general lock directory
    lock_re = re.compile(r'^\.X([0-9]+)-lock$')
    lock_files = [f for f in listdir(LOCKDIR) if lock_re.match(f)]
    displays = [int(lock_re.search(f).group(1)) for f in lock_files]
    open_display = min([i for i in range(0, max(displays) + 2) if i not in displays])
    return open_display

def start_server(display):
    xvfb = Popen([XVFB, ':%d' % display])
    # wait for the lock file to make sure the server is running
    lockfile = path.join(LOCKDIR, '.X%d-lock' % display)
    tries = 0
    while True:
        if path.exists(lockfile):
            break
        else:<commit_msg>test-suite: handle no displays<commit_after>#!/usr/bin/env python3

import subprocess
from subprocess import Popen
import os
from os import listdir, path
from os.path import isfile, join
from shutil import which
import sys
import re
import time

PYTEST = 'py.test-3.5'
XVFB = 'Xvfb'
I3_BINARY = 'i3'
LOCKDIR = '/tmp'

def check_dependencies():
    if not which(XVFB):
        # TODO make this optional
        print('Xvfb is required to run tests')
        print('Command "%s" not found in PATH' % XVFB)
        sys.exit(127)

    if not which(I3_BINARY):
        print('i3 binary is required to run tests')
        print('Command "%s" not found in PATH' % I3_BINARY)
        sys.exit(127)

def get_open_display():
    # TODO find the general lock directory
    lock_re = re.compile(r'^\.X([0-9]+)-lock$')
    lock_files = [f for f in listdir(LOCKDIR) if lock_re.match(f)]
    displays = [int(lock_re.search(f).group(1)) for f in lock_files]
    open_display = min([i for i in range(0, max(displays or [0]) + 2) if i not in displays])
    return open_display

def start_server(display):
    xvfb = Popen([XVFB, ':%d' % display])
    # wait for the lock file to make sure the server is running
    lockfile = path.join(LOCKDIR, '.X%d-lock' % display)
    tries = 0
    while True:
        if path.exists(lockfile):
            break
        else:
{'fraction_non_alphanumeric': 0.11477869467366841, 'fraction_numerical': 0.015378844711177795, 'mean_word_length': 2.998500749625187, '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': '50633', 'n_tokens_mistral': 924, 'n_tokens_neox': 897, 'n_words': 300}