def test_wrap(): e = EnhancedTextWrapper(width=40) text = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna " + "aliqua. Ut enim ad minim veniam, quis nostrud exercitation " + "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis " + "aute irure dolor in reprehenderit in voluptate velit esse " + "cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat " + "cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum.") assert e.fill(text) == strip_margin( """|Lorem ipsum dolor sit amet, consectetur |adipiscing elit, sed do eiusmod tempor |incididunt ut labore et dolore magna |aliqua. Ut enim ad minim veniam, quis |nostrud exercitation ullamco laboris |nisi ut aliquip ex ea commodo consequat. |Duis aute irure dolor in reprehenderit |in voluptate velit esse cillum dolore eu |fugiat nulla pariatur. Excepteur sint |occaecat cupidatat non proident, sunt in |culpa qui officia deserunt mollit anim |id est laborum.""") e = EnhancedTextWrapper(width=70) assert e.fill(text) == strip_margin( """|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do |eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad |minim veniam, quis nostrud exercitation ullamco laboris nisi ut |aliquip ex ea commodo consequat. Duis aute irure dolor in |reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla |pariatur. Excepteur sint occaecat cupidatat non proident, sunt in |culpa qui officia deserunt mollit anim id est laborum.""") e = EnhancedTextWrapper(width=70, subsequent_indent=" ") assert e.fill(text) == strip_margin( """|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim | ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut | aliquip ex ea commodo consequat. Duis aute irure dolor in | reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla | pariatur. Excepteur sint occaecat cupidatat non proident, sunt in | culpa qui officia deserunt mollit anim id est laborum.""") e = EnhancedTextWrapper(width=70) text = ("Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, " + "sed do eiusmod tempor\nincididunt ut labore et dolore magna " + "aliqua. Ut enim ad minim veniam, quis nostrud exercitation") assert e.fill(text) == strip_margin("""|Lorem ipsum dolor sit amet, |consectetur adipiscing elit, sed do eiusmod tempor |incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, |quis nostrud exercitation""")
def base_config(): return strip_margin("""|[foo] |host: https://foo.cloud.databricks.com |token: kjhadsfkjhasdflkjhasdf |[bar] |host: https://bar.cloud.databricks.com |token: kjhadsfkjhasdflkjhasdf |home: /Users/[email protected] |[empty] |#empty |[missing_host] |# Missing host |token: sdakjhqreiuyhkjasdfjklasdf |home: /Users/[email protected] |[missing_token] |# Missing token |host: https://toad.cloud.databricks.com |home: /Users/[email protected] |[missing_home] |# Missing token |token: sadfuiy23894uihjksafdhkjl |host: https://home.cloud.databricks.com |[has_user_not_home] |token: sadfuiy23894uihjksafdhkjl |host: https://home.cloud.databricks.com |username: [email protected] |""")
def config_with_default() -> str: with TemporaryDirectory() as dir: path = os.path.join(dir, "dbcfg2") with open(path, "w") as f: default = strip_margin("""|[DEFAULT] |host: https://default.cloud.databricks.com |token: default_token |home: /Users/[email protected] """) print(default + base_config()) f.write(default + base_config()) if os.environ.get("DB_SHARD_HOME"): del os.environ["DB_SHARD_HOME"] yield path
def config() -> str: with TemporaryDirectory() as dir: path = os.path.join(dir, 'dbcfg') with open(path, 'w') as f: f.write( strip_margin('''|[foo] |host: https://foo.cloud.databricks.com |token: kjhadsfkjhasdflkjhasdf |[bar] |host: https://bar.cloud.databricks.com |token: kjhadsfkjhasdflkjhasdf |home: /Users/[email protected] |[baz] |host: https://baz.cloud.databricks.com |token: kjhadsfkjhasdflkjhasdf |username: [email protected] |''')) yield path
def test_strip_margin(): assert strip_margin('''|abc |def |ghi''') == 'abc\ndef\nghi' assert strip_margin('''|abc |def |ghi ''') == 'abc\ndef\nghi\n' assert strip_margin('''|abc |def |ghi |''') == 'abc\ndef\nghi\n' assert strip_margin('''|abc | |ghi |''') == 'abc\n\nghi\n' assert strip_margin('''|abc |ghi |''') == 'abc\n\nghi\n' assert strip_margin('''|abc oops |ghi |''') == 'abc\noops\nghi\n'
def test_strip_margin(): assert (strip_margin("""|abc |def |ghi""") == "abc\ndef\nghi") assert (strip_margin("""|abc |def |ghi """) == "abc\ndef\nghi\n") assert (strip_margin("""|abc |def |ghi |""") == "abc\ndef\nghi\n") assert (strip_margin("""|abc | |ghi |""") == "abc\n\nghi\n") assert (strip_margin("""|abc |ghi |""") == "abc\n\nghi\n") assert (strip_margin("""|abc oops |ghi |""") == "abc\noops\nghi\n")