From ebfb04ea083d0cf50be5dc8dd03edffcea12cd4f Mon Sep 17 00:00:00 2001 From: mansenfranzen Date: Fri, 22 Mar 2019 14:21:06 +0100 Subject: [PATCH] Add and adjust tests for `enumeration` and `sizeof`. --- tests/util/test_pprint.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/util/test_pprint.py b/tests/util/test_pprint.py index eb3967e..35a71b0 100644 --- a/tests/util/test_pprint.py +++ b/tests/util/test_pprint.py @@ -2,13 +2,10 @@ """ -import pytest - from pywrangler.util import _pprint def test_join(): - test_input = ["a", "b", "c"] test_output = "a\nb\nc" @@ -16,7 +13,6 @@ def test_join(): def test_indent(): - test_input = ["a", "b", "c"] test_output = [" a", " b", " c"] @@ -24,7 +20,6 @@ def test_indent(): def test_header(): - test_input = "Header" test_output = 'Header\n------\n' @@ -32,7 +27,6 @@ def test_header(): def test_header_with_indent(): - test_input = "Header" test_output = ' Header\n ------\n' @@ -40,23 +34,34 @@ def test_header_with_indent(): def test_header_with_underline(): - test_input = "Header" test_output = 'Header\n======\n' assert _pprint.header(test_input, underline="=") == test_output -def test_enumeration_dict(): +def test_enumeration_dict_align_values_false(): + test_input = {"a": 1, "bb": 2} + test_output = '- a: 1\n- bb: 2' + + assert _pprint.enumeration(test_input, align_values=False) == test_output + - test_input = {"a": 1, "b": 2} - test_output = '- a: 1\n- b: 2' +def test_enumeration_dict_align_values(): + test_input = {"a": 1, "bb": 2} + test_output = '- a: 1\n- bb: 2' assert _pprint.enumeration(test_input) == test_output -def test_enumeration_list(): +def test_enumeration_dict_align_values_with_align_width(): + test_input = {"a": 1, "bb": 2} + test_output = '- a: 1\n- bb: 2' + + assert _pprint.enumeration(test_input, align_width=3) == test_output + +def test_enumeration_list(): test_input = ["note 1", "note 2"] test_output = '- note 1\n- note 2' @@ -64,7 +69,6 @@ def test_enumeration_list(): def test_enumeration_list_with_indent(): - test_input = ["note 1", "note 2"] test_output = ' - note 1\n - note 2' @@ -72,8 +76,15 @@ def test_enumeration_list_with_indent(): def test_enumeration_list_with_bullet(): - test_input = ["note 1", "note 2"] test_output = 'o note 1\no note 2' assert _pprint.enumeration(test_input, bullet_char="o") == test_output + + +def test_sizeof(): + assert _pprint.sizeof(1024, precision=1, width=0) == '1.0 KiB' + assert _pprint.sizeof(1024, precision=1) == ' 1.0 KiB' + assert _pprint.sizeof(1024, precision=1, align="<") == '1.0 KiB' + assert _pprint.sizeof(1024 ** 2, precision=1, width=0) == '1.0 MiB' + assert _pprint.sizeof(1024 ** 8, precision=2, width=0) == '1.00 YiB'