Skip to content

Commit 6b88738

Browse files
committed
case_sensitive
1 parent 339a0c1 commit 6b88738

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pip install ycleptic
1818
Once installed, the developer has access to the ``Yclept`` class.
1919

2020
## Release History
21+
* 1.4.0
22+
* `case_sensitive` boolean attribute enabled for all `str`-types
2123
* 1.3.0
2224
* `__init__` optionally accepts a dict instead of only a file name
2325
* 1.2.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["hatchling"]
33
build-backend = "hatchling.build"
44
[project]
55
name = "ycleptic"
6-
version = "1.3.0"
6+
version = "1.4.0"
77
authors = [
88
{ name="Cameron F Abrams", email="cfa22@drexel.edu" },
99
]

tests/test_set.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ def test_user_dump(self):
101101
tv=user_dump['directive_3']['directive_3_1']['directive_3_1_1']['directive_3_1_1_1']['d3111v1']
102102
self.assertEqual(tv,'ABC')
103103

104+
def test_case_insensitive(self):
105+
example1="""
106+
directive_4: abc123
107+
"""
108+
with open('example1.yaml','w') as f:
109+
f.write(example1)
110+
bdir=os.path.dirname(resources.__file__)
111+
bfile=os.path.join(bdir,'example_base.yaml')
112+
ufile=os.path.join('example1.yaml')
113+
Y=Yclept(bfile,userfile=ufile)
114+
os.remove('example1.yaml')
115+
self.assertTrue('directive_4' in Y["user"])
116+
self.assertEqual(Y['user']['directive_4'],'ABC123')
117+
104118
def test_dotfile1(self):
105119
example1="""
106120
directive_2:

tests/test_set/example1.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

ycleptic/resources/example_base.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@ directives:
113113
- name: filename
114114
type: str
115115
text: name of file to save
116-
default: flipfile.dat
116+
default: flipfile.dat
117+
- name: directive_4
118+
type: str
119+
text: This is a description of Directive 4
120+
case_sensitive: False

ycleptic/yclept.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,14 @@ def _dwalk(D,I):
405405
I[d]=dx.get('default',[])
406406
# this directive does appear in I
407407
else:
408-
if typ=='str' and 'choices' in dx:
408+
if typ=='str':
409+
case_sensitive=dx.get('case_sensitive',True)
410+
# logger.debug(f'case_sensitive {case_sensitive}')
411+
if not case_sensitive:
412+
I[d]=I[d].upper()
413+
if 'choices' in dx:
409414
# just check the choices that were provided by the user
410-
assert I[d] in dx['choices'],f'Directive \'{d}\' of \'{dx["name"]}\' must be one of {", ".join(dx["choices"])}'
415+
assert I[d] in dx['choices'],f'Directive \'{d}\' of \'{dx["name"]}\' must be one of {", ".join(dx["choices"])}'
411416
elif typ=='dict':
412417
# process descendants
413418
if 'directives' in dx:

0 commit comments

Comments
 (0)