Selfie
Loading...
Searching...
No Matches
selfie_lib.SnapshotSystem.Mode Class Reference
Inheritance diagram for selfie_lib.SnapshotSystem.Mode:

Public Member Functions

bool can_write (self, bool is_todo, CallStack call, SnapshotSystem system)
 
str msg_snapshot_not_found (self)
 
str msg_snapshot_not_found_no_such_file (self, file)
 
str msg_snapshot_mismatch (self, str expected, str actual)
 
str msg_snapshot_mismatch_binary (self, bytes expected, bytes actual)
 
str msg (self, str headline)
 

Static Public Attributes

 interactive = auto()
 
 readonly = auto()
 
 overwrite = auto()
 

Protected Member Functions

str _to_quoted_printable (self, bytes byte_data)
 

Detailed Description

Definition at line 99 of file SnapshotSystem.py.

Member Function Documentation

◆ _to_quoted_printable()

str selfie_lib.SnapshotSystem.Mode._to_quoted_printable (   self,
bytes  byte_data 
)
protected

Definition at line 137 of file SnapshotSystem.py.

137 def _to_quoted_printable(self, byte_data: bytes) -> str:
138 result = []
139 for b in byte_data:
140 # b is already an integer in [0..255] when iterating through a bytes object
141 if 33 <= b <= 126 and b != 61: # '=' is ASCII 61, so skip it
142 result.append(chr(b))
143 else:
144 # Convert to uppercase hex, pad to 2 digits, and prepend '='
145 result.append(f"={b:02X}")
146 return "".join(result)
147

◆ can_write()

bool selfie_lib.SnapshotSystem.Mode.can_write (   self,
bool  is_todo,
CallStack  call,
SnapshotSystem  system 
)

Definition at line 104 of file SnapshotSystem.py.

104 def can_write(self, is_todo: bool, call: CallStack, system: SnapshotSystem) -> bool:
105 if self == Mode.interactive:
106 return is_todo or system.source_file_has_writable_comment(call)
107 elif self == Mode.readonly:
108 if system.source_file_has_writable_comment(call):
109 layout = system.layout
110 path = layout.sourcefile_for_call(call.location)
111 comment, line = CommentTracker.commentString(path)
112 raise system.fs.assert_failed(
113 f"Selfie is in readonly mode, so `{comment}` is illegal at {call.location.with_line(line).ide_link(layout)}"
114 )
115 return False
116 elif self == Mode.overwrite:
117 return True
118 else:
119 raise ValueError(f"Unknown mode: {self}")
120

◆ msg()

str selfie_lib.SnapshotSystem.Mode.msg (   self,
str  headline 
)

Definition at line 148 of file SnapshotSystem.py.

148 def msg(self, headline: str) -> str:
149 if self == Mode.interactive:
150 return (
151 f"{headline}\n"
152 "- update this snapshot by adding `_TODO` to the function name\n"
153 "- update all snapshots in this file by adding `#selfieonce` or `#SELFIEWRITE`"
154 )
155 elif self == Mode.readonly:
156 return headline
157 elif self == Mode.overwrite:
158 return f"{headline}\n(didn't expect this to ever happen in overwrite mode)"
159 else:
160 raise ValueError(f"Unknown mode: {self}")

◆ msg_snapshot_mismatch()

str selfie_lib.SnapshotSystem.Mode.msg_snapshot_mismatch (   self,
str  expected,
str  actual 
)

Definition at line 127 of file SnapshotSystem.py.

127 def msg_snapshot_mismatch(self, expected: str, actual: str) -> str: # noqa: ARG002
128 return self.msg(
129 "Snapshot mismatch (error msg could be better https://github.com/diffplug/selfie/issues/501)"
130 )
131

◆ msg_snapshot_mismatch_binary()

str selfie_lib.SnapshotSystem.Mode.msg_snapshot_mismatch_binary (   self,
bytes  expected,
bytes  actual 
)

Definition at line 132 of file SnapshotSystem.py.

132 def msg_snapshot_mismatch_binary(self, expected: bytes, actual: bytes) -> str:
133 return self.msg_snapshot_mismatch(
134 self._to_quoted_printable(expected), self._to_quoted_printable(actual)
135 )
136

◆ msg_snapshot_not_found()

str selfie_lib.SnapshotSystem.Mode.msg_snapshot_not_found (   self)

Definition at line 121 of file SnapshotSystem.py.

121 def msg_snapshot_not_found(self) -> str:
122 return self.msg("Snapshot not found")
123

◆ msg_snapshot_not_found_no_such_file()

str selfie_lib.SnapshotSystem.Mode.msg_snapshot_not_found_no_such_file (   self,
  file 
)

Definition at line 124 of file SnapshotSystem.py.

124 def msg_snapshot_not_found_no_such_file(self, file) -> str:
125 return self.msg(f"Snapshot not found: no such file {file}")
126

Member Data Documentation

◆ interactive

selfie_lib.SnapshotSystem.Mode.interactive = auto()
static

Definition at line 100 of file SnapshotSystem.py.

◆ overwrite

selfie_lib.SnapshotSystem.Mode.overwrite = auto()
static

Definition at line 102 of file SnapshotSystem.py.

◆ readonly

selfie_lib.SnapshotSystem.Mode.readonly = auto()
static

Definition at line 101 of file SnapshotSystem.py.


The documentation for this class was generated from the following file: