Skip to content

52nd Week of 2021

Coding

Python

Dash

  • New: Test programs that use sh.

    sh can be patched in your tests the typical way, with unittest.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

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()
    

SQLite