From ef7b2b7eaf8f6f786133869e0b22cfdda15844a8 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Wed, 7 Nov 2018 13:31:33 +0100 Subject: [PATCH 1/2] Fix FormattedString test failure. Initialize FormattedString().attributes to DEFAULT_ATTRIBUTES so all the attributes are always present. FormattedString is now a class, not a namedtuple instance. --- matrix/colors.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/matrix/colors.py b/matrix/colors.py index 261a5bd..96a4c24 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -43,7 +43,13 @@ except ImportError: from html.parser import HTMLParser -FormattedString = namedtuple("FormattedString", ["text", "attributes"]) +class FormattedString: + __slots__ = ("text", "attributes") + + def __init__(self, text, attributes): + self.attributes = DEFAULT_ATTRIBUTES.copy() + self.attributes.update(attributes) + self.text = text class Formatted(object): From 2022151bd0f06f138d8c1bf3dec43f5affe6b5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 7 Nov 2018 13:50:55 +0100 Subject: [PATCH 2/2] tests: Add initial buffer tests. --- matrix/_weechat.py | 6 ++++++ tests/buffer_test.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/buffer_test.py diff --git a/matrix/_weechat.py b/matrix/_weechat.py index 54cbe37..346b67f 100644 --- a/matrix/_weechat.py +++ b/matrix/_weechat.py @@ -154,6 +154,12 @@ def buffer_set(*_, **__): return +def buffer_get_string(_ptr, property): + if property == "localvar_type": + return "channel" + return "" + + def nicklist_add_group(*_, **__): return diff --git a/tests/buffer_test.py b/tests/buffer_test.py new file mode 100644 index 0000000..e146ac5 --- /dev/null +++ b/tests/buffer_test.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals + +from matrix.buffer import WeechatChannelBuffer + + +class TestClass(object): + def test_buffer(self): + b = WeechatChannelBuffer("test_buffer_name", "example.org", "alice") + assert b + + def test_buffer_print(self): + b = WeechatChannelBuffer("test_buffer_name", "example.org", "alice") + b.message("alice", "hello world", 0, 0) + assert b