Skip to content

Commit

Permalink
steno_dictionary: fix handling of read-only flag
Browse files Browse the repository at this point in the history
If the class implementation is marked as read-only,
then loading from a writable file should still
result in a read-only dictionary.
  • Loading branch information
benoit-pierre committed Apr 29, 2021
1 parent 03c4915 commit 97fb12a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plover/steno_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def load(cls, resource):
timestamp = resource_timestamp(filename)
d = cls()
d._load(filename)
if resource.startswith(ASSET_SCHEME) or \
not os.access(filename, os.W_OK):
if (cls.readonly or
resource.startswith(ASSET_SCHEME) or
not os.access(filename, os.W_OK)):
d.readonly = True
d.path = resource
d.timestamp = timestamp
Expand Down
8 changes: 8 additions & 0 deletions plover_build_utils/testing/steno_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def parse_entries(entries):
for k, v in ast.literal_eval('{' + entries + '}').items()
}

def test_readonly_writable_file(self, tmp_path):
'''
Writable file: match class read-only attribute.
'''
with self.sample_dict(tmp_path) as dict_path:
d = self.DICT_CLASS.load(str(dict_path))
assert d.readonly == self.DICT_CLASS.readonly

def test_readonly_readonly_file(self, tmp_path):
'''
Read-only file: read-only dictionary.
Expand Down

0 comments on commit 97fb12a

Please sign in to comment.