<commit_before>package logging

import (
	"bytes"
	"errors"
	"os"
	"strings"
	"syscall"
	"testing"
	"time"
)

var h *BaseHandler
var b *bytes.Buffer

func init() {
	b = bytes.NewBuffer(nil)
	var err error
	h, err = NewBaseHandler(b, DEBUG, DefaultTimeLayout, DefaultFormat)
	if err != nil {
		panic(err)
	}
	DisableStdout()
}

func TestSetBufSize(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	Debug("%d, %s", 1, "OK")
	h.SetBufSize(1)
	if h.BufSize != 1 {
		t.Fail()
	}
	Debug("%d, %s", 2, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 68 {
		t.Fail()
	}
}

func TestSetLevel(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	Debug("%d, %s", 1, "OK")
	h.SetLevel(INFO)
	Debug("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34 {
		t.Fail()
	}
}

func TestSetLevelString(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	Debug("%d, %s", 1, "OK")
	h.SetLevelString("info")
	Debug("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34 {
		t.Fail()
	}
}

func TestSetLevelRange(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	h.SetLevelRange(INFO, WARNING)
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34*4-2 {
		t.Fail()
	}
}

func TestSetLevelRangeString(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	h.SetLevelRangeString("INFO", "WARNING")
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34*4-2 {
		t.Fail()
	}
}

func TestSetTimeLayout(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetTimeLayout("2006/01/02-15:04:05")
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34 {
		t.Fail()
	}
}

func TestSetFilter(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetFilter(func(rd *Record) bool {
		return strings.Contains(rd.Message, "OK")
	})
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 0 {
		t.Fail()
	}
}

func TestPanicError(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetFilter(func(*Record) bool {
		panic(errors.New("nothing"))
		return true
	})
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if h.get_state() {
		t.Fail()
	}
	h.set_state(true)
}

func TestNotify(t *testing.T) {
	h.set_state(false)
	p, _ := os.FindProcess(os.Getpid())
	p.Signal(syscall.SIGHUP)
	time.Sleep(100 * time.Millisecond)
	if !h.get_state() {
		t.Fail()
	}
	h.set_state(true)
}<commit_msg>to fix sublime text test all<commit_after>package logging

import (
	"bytes"
	"errors"
	"os"
	"strings"
	"syscall"
	"testing"
	"time"
)

var h *BaseHandler
var b *bytes.Buffer

func init() {
	b = bytes.NewBuffer(nil)
	var err error
	h, err = NewBaseHandler(b, DEBUG, DefaultTimeLayout, DefaultFormat)
	if err != nil {
		panic(err)
	}
	DisableStdout()
}

func TestSetBufSize(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	Debug("%d, %s", 1, "OK")
	h.SetBufSize(128)
	if h.BufSize != 128 {
		t.Fail()
	}
	Debug("%d, %s", 2, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 68 {
		t.Fail()
	}
}

func TestSetLevel(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	Debug("%d, %s", 1, "OK")
	h.SetLevel(INFO)
	Debug("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34 {
		t.Fail()
	}
}

func TestSetLevelString(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	Debug("%d, %s", 1, "OK")
	h.SetLevelString("info")
	Debug("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34 {
		t.Fail()
	}
}

func TestSetLevelRange(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	h.SetLevelRange(INFO, WARNING)
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34*4-2 {
		t.Fail()
	}
	h.LRange = nil
}

func TestSetLevelRangeString(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	h.SetLevelRangeString("INFO", "WARNING")
	Debug("%d, %s", 1, "OK")
	Info("%d, %s", 1, "OK")
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34*4-2 {
		t.Fail()
	}
	h.LRange = nil
}

func TestSetTimeLayout(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	h.SetTimeLayout("2006/01/02-15:04:05")
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 34 {
		t.Fail()
	}
	h.SetTimeLayout(DefaultTimeLayout)
}

func TestSetFilter(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	h.SetFilter(func(rd *Record) bool {
		return strings.Contains(rd.Message, "OK")
	})
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if b.Len() != 0 {
		t.Fail()
	}
	h.SetFilter(nil)
}

func TestPanicError(t *testing.T) {
	b.Reset()
	AddHandler("b", h)
	h.SetLevel(DEBUG)
	h.SetFilter(func(*Record) bool {
		panic(errors.New("nothing"))
		return true
	})
	Error("%d, %s", 1, "OK")
	time.Sleep(100 * time.Millisecond)
	if h.get_state() {
		t.Fail()
	}
	h.set_state(true)
	h.SetFilter(nil)
}

func TestNotify(t *testing.T) {
	h.set_state(false)
	p, _ := os.FindProcess(os.Getpid())
	p.Signal(syscall.SIGHUP)
	time.Sleep(100 * time.Millisecond)
	if !h.get_state() {
		t.Fail()
	}
	h.set_state(true)
}
{'fraction_non_alphanumeric': 0.23204919515283054, 'fraction_numerical': 0.030023512389220474, 'mean_word_length': 3.9596412556053813, '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': '6461706', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2539, 'n_words': 520}