From c22bcd290f3a2a572a8fdeee8206ef09ea7b9792 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 19 Feb 2020 16:22:22 -0800 Subject: [PATCH] Add pathclass.assert_exists and assert_not_exists. --- voussoirkit/pathclass.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 0bd6c98..3566781 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -6,11 +6,15 @@ import re class PathclassException(Exception): pass +class Exists(PathclassException): + pass + +class NotExists(PathclassException): + pass class NotDirectory(PathclassException): pass - class NotFile(PathclassException): pass @@ -96,6 +100,14 @@ class Path: def __repr__(self): return '{c}({path})'.format(c=self.__class__.__name__, path=repr(self.absolute_path)) + def assert_exists(self): + if not self.exists: + raise NotExists(self) + + def assert_not_exists(self): + if self.exists: + raise Exists(self) + def assert_is_file(self): if not self.is_file: raise NotFile(self)