52nd Week of 2021
Coding⚑
Python⚑
Dash⚑
-
New: Test programs that use
sh
.sh
can be patched in your tests the typical way, withunittest.mock.patch()
:from unittest.mock import patch import sh def get_something(): return sh.pwd() @patch("sh.pwd", create=True) def test_something(pwd): pwd.return_value = "/" assert get_something() == "/"
Python Snippets⚑
-
New: Change the logging level of a library.
sh_logger = logging.getLogger("sh") sh_logger.setLevel(logging.WARN)
-
New: Get all subdirectories of a directory.
[x[0] for x in os.walk(directory)]
-
New: Move a file.
import os os.rename("path/to/current/file.foo", "path/to/new/destination/for/file.foo")
-
New: Copy a file.
import shutil shutil.copyfile(src_file, dest_file)
questionary⚑
-
New: Conditionally skip questions.
Sometimes it is helpful to be able to skip a question based on a condition. To avoid the need for an if around the question, you can pass the condition when you create the question:
import questionary DISABLED = True response = questionary.confirm("Are you amazed?").skip_if(DISABLED, default=True).ask()
-
New: Don't highlight the selected option by default.
If you don't want to highlight the default choice in the
select
question use the next style:from questionary import Style choice = select( "Question title: ", choices=['a', 'b', 'c'], default='a', style=Style([("selected", "noreverse")]), ).ask()