예제 #1
0
def inform(message):
    """
    Args:
        message: Message to print and log at level INFO
    """
    message = runez.stringified(message)
    print(message)
    _log_to_file(message)
예제 #2
0
    def track_result_combination(self, impl, data):
        if isinstance(data, Exception):
            value = runez.stringified(data)

        else:
            value = runez.represented_json(data,
                                           stringify=decode,
                                           keep_none=True,
                                           none_key="-null-")

        name = impl.name
        if self.combinations is None:
            self.combinations = {}
            for i1 in self.selected:
                for i2 in self.selected:
                    if i1.name < i2.name:
                        self.combinations[(i1.name, i2.name)] = set()

        for names, values in self.combinations.items():
            if name in names:
                values.add(value)
예제 #3
0
def abort(message):
    message = runez.stringified(message)
    print(message)
    _log_to_file(message, error=True)
    sys.exit(1)
예제 #4
0
def check_spec(text, canonical):
    d = PythonSpec(text)
    assert d.text == runez.stringified(text).strip()
    assert str(d) == canonical
예제 #5
0
def test_stringified():
    assert runez.stringified(None) == "None"
    assert runez.stringified(None, none=None) == "None"
    assert runez.stringified(None, none=False) == ""
    assert runez.stringified(None, none=True) == "None"
    assert runez.stringified(None, none=0) == "0"
    assert runez.stringified(None, none=1) == "1"
    assert runez.stringified(None, none="null") == "null"
    assert runez.stringified("", none="null") == ""
    assert runez.stringified(5) == "5"
    assert runez.stringified(b"foo") == "foo"
    assert runez.stringified(
        [0, None, 1], none="null"
    ) == "[0, None, 1]"  # `none=` applies only to values (not items in lists etc...)
    assert runez.stringified(
        [1, 2], converter=lambda x: None
    ) == "[1, 2]"  # If converter returns None, we keep the value
    assert runez.stringified(5,
                             converter=lambda x: x) == "5"  # No-op converter