How to use should_handle method in Slash

Best Python code snippet using slash

hevi_list.py

Source:hevi_list.py Github

copy

Full Screen

...13 ((".zip",), "unzip", "-l"),14 ((".deb",), "dpkg-deb", "--contents")15)16class File(object):17 def should_handle(self,path):18 return False19 def list(self,path):20 raise NotImplementedError21 22class Reg(File):23 def should_handle(self,path):24 return True25 def list(self,path):26 cmd = "less"27 options = "-M" # long prompt28 cmdline = "%(cmd)s %(options)s %(path)s" % vars()29 os.system(cmdline)30 31class Dir(File):32 def should_handle(self,path):33 return os.path.isdir(path)34 def list(self,path):35 cmd = "ls"36 options = "-lLF" # long format, deference symlink,classify37 cmdline = "%(cmd)s %(options)s %(path)s" % vars()38 os.system(cmdline)39class FileExt(File):40 def __init__(self,suffixes,cmd,options):41 self._suffixes = suffixes42 self._cmd = cmd43 self._options = options44 def should_handle(self,path):45 for suffix in self._suffixes:46 if path.endswith(suffix):47 return True48 return False49 def list(self,path):50 cmd = self._cmd51 options = self._options52 cmdline = "%(cmd)s %(options)s %(path)s" % vars()53 os.system(cmdline)54 55################################################################################56class Main(object):57 def __init__(self):58 self._handlers = list()59 self._handlers_init()60 def run(self):61 args = sys.argv[1:]62 if len(args) == 0:63 args.append(".")64 for arg in args:65 handler = self._resolve_handler(arg) 66 handler.list(arg)67 68 def _handlers_init(self):69 self._handlers.append(Dir()) 70 for mapping in typemap:71 self._handlers.append(FileExt(*mapping))72 self._handlers.append(Reg())73 def _resolve_handler(self,path):74 for handler in self._handlers:75 if handler.should_handle(path):76 return handler77 return None78################################################################################79if __name__ == '__main__':80 Main().run()81################################################################################82# Local Variables:83# mode: python84# indent-tabs-mode: nil85# py-indent-offset: 2...

Full Screen

Full Screen

default_handlers.py

Source:default_handlers.py Github

copy

Full Screen

...9from .named_types import NamedLiteral, NamedUnion10from .store import BasicHandler, ClassHandler, TypeStoreType11# Union is not really a type12class UnionHandler(BasicHandler[Any, TypeStoreType]):13 def should_handle(self, cls, origin, args) -> bool:14 return origin in (NamedUnion, Union)15class LiteralHandler(BasicHandler[Any, TypeStoreType]):16 def should_handle(self, cls, origin, args) -> bool:17 return origin in (Literal, NamedLiteral)18class EnumHandler(ClassHandler[Any, TypeStoreType]):19 def should_handle(self, cls: type, origin, args) -> bool:20 return issubclass(cls, Enum)21class DataclassHandler(ClassHandler[Any, TypeStoreType]):22 def is_mapping(self) -> bool:23 return True24 def should_handle(self, cls: type, origin, args) -> bool:25 return is_dataclass(cls)26class TupleHandler(BasicHandler[Any, TypeStoreType]):27 def should_handle(self, cls: Any, origin: Optional[type], args: List[Any]) -> bool:28 return origin is tuple29class ArrayHandler(BasicHandler[Any, TypeStoreType]):30 def should_handle(self, cls: Any, origin: Optional[type], args: List[Any]) -> bool:31 return origin == list and len(args) == 132class MappingHandler(BasicHandler[Any, TypeStoreType]):33 def should_handle(self, cls: Any, origin: Optional[type], args: List[Any]) -> bool:...

Full Screen

Full Screen

test_reloader.py

Source:test_reloader.py Github

copy

Full Screen

...4import staticjinja5@pytest.fixture6def reloader(site: staticjinja.Site) -> staticjinja.Reloader:7 return staticjinja.Reloader(site)8def test_should_handle(9 reloader: staticjinja.Reloader,10 root_path: Path,11 template_path: Path,12) -> None:13 exists = template_path / "template1.html"14 DNE = template_path / "DNE.html"15 assert reloader.should_handle("created", str(exists))16 assert reloader.should_handle("modified", str(exists))17 assert not reloader.should_handle("deleted", str(exists))18 assert not reloader.should_handle("modified", str(DNE))19def test_event_handler(20 monkeypatch: pytest.MonkeyPatch,21 reloader: staticjinja.Reloader,22 template_path: Path,23) -> None:24 rendered = []25 def fake_renderer(template, context=None, filepath=None):26 rendered.append(template)27 monkeypatch.setattr(reloader.site, "render_template", fake_renderer)28 template1_path = str(template_path.joinpath("template1.html"))29 reloader.event_handler("modified", template1_path)30 assert rendered == [reloader.site.get_template("template1.html")]31def test_event_handler_static(32 monkeypatch: pytest.MonkeyPatch,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful