Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from pprint import pformat
from py3status.py3 import Py3
py3 = Py3()
def test_format_units():
tests = [
# basic unit guessing
(dict(value=100), (100, "B")),
(dict(value=999), (999, "B")),
(dict(value=1000), (0.977, "KiB")),
(dict(value=1024), (1.0, "KiB")),
(dict(value=pow(1024, 2)), (1.0, "MiB")),
(dict(value=pow(1024, 3)), (1.0, "GiB")),
(dict(value=pow(1024, 4)), (1.0, "TiB")),
(dict(value=pow(1024, 5)), (1.0, "PiB")),
# no guessing
(dict(value=pow(1024, 2), auto=False), (pow(1024, 2), "B")),
"""
Run formatter tests
"""
import platform
from pprint import pformat
import pytest
from py3status.composite import Composite
from py3status.formatter import Formatter
from py3status.py3 import NoneColor
is_pypy = platform.python_implementation() == "PyPy"
f = Formatter()
param_dict = {
"name": "Björk",
"number": 42,
"pi": 3.14159265359,
"yes": True,
"no": False,
"empty": "",
"None": None,
"?bad name": "evil",
"☂ Very bad name ": "☂ extremely evil",
"long_str": "I am a long string though not too long",
"python2_unicode": "Björk",
"python2_str": "Björk",
"zero": 0,
"zero_str": "0",
def make_status_wrapper():
args = argparse.Namespace()
status_wrapper = Py3statusWrapper(args)
return status_wrapper
def check_docstrings():
all_errors = []
docstrings = core_module_docstrings()
for module_name in sorted(docstrings.keys()):
errors = []
if module_name in IGNORE_MODULE:
continue
path = os.path.join(MODULE_PATH, "%s.py" % module_name)
mod_config = get_module_attributes(path)
params, obsolete = docstring_params(docstrings[module_name])
if list(params.keys()) != list(sorted(params.keys())):
keys = list(params.keys())
msg = "config params not in alphabetical order should be\n{keys}"
errors.append(msg.format(keys=_gen_diff(keys, sorted(keys))))
if list(obsolete.keys()) != list(sorted(obsolete.keys())):
keys = list(obsolete.keys())
obj["color"] = color
output.append(obj)
composites = {"output": self.py3.composite_create(output)}
rainbow = self.py3.safe_format(self.format, composites)
return {"cached_until": self._cycle_time, "full_text": rainbow}
if __name__ == "__main__":
"""
Run module in test mode.
"""
from py3status.module_test import module_test
module_test(Py3status)
msg = "This GPU contains {} supported properties."
for line in gpu_data.splitlines():
gpu = dict(zip(new_properties, line.split(", ")))
gpu = {k: v for k, v in gpu.items() if "[Not Supported]" not in v}
gpu["= " + msg.format(len(gpu))] = ""
gpu["=" * (len(msg) + 2)] = ""
new_gpus.append(gpu)
print(dumps(new_gpus, sort_keys=True, indent=4))
exit()
"""
Run module in test mode.
"""
from py3status.module_test import module_test
module_test(Py3status)
if "DPMS is Enabled" in self.py3.command_output("xset -q"):
self.py3.command_run("xset -dpms s off")
else:
self.py3.command_run("xset +dpms s on")
if event["button"] == self.button_off:
self.py3.command_run("xset dpms force off")
if __name__ == "__main__":
"""
Run module in test mode.
"""
from py3status.module_test import module_test
module_test(Py3status)
return response
def on_click(self, event):
button = event["button"]
if button == self.button_show_notification:
self.py3.notify_user(self.output)
self.py3.prevent_refresh()
if __name__ == "__main__":
"""
Run module in test mode.
"""
from py3status.module_test import module_test
module_test(Py3status)
def on_click(self, event):
button = event["button"]
if button == self.button_next:
self._set_active(1)
if button == self.button_prev:
self._set_active(-1)
if __name__ == "__main__":
"""
Run module in test mode.
"""
from py3status.module_test import module_test
module_test(Py3status)
return {
"cached_until": self.py3.time_in(self.cache_timeout),
"color": color,
"full_text": self.py3.safe_format(
self.format, {"icon": icon, "process": self.process}
),
}
if __name__ == "__main__":
"""
Run module in test mode.
"""
from py3status.module_test import module_test
module_test(Py3status)