test config, rename to chooseCards

a hyphen - looks weird in a python file and module name, so use CamelCase
This commit is contained in:
Bela 2019-08-26 17:38:12 +02:00
parent 8857f49997
commit ef03d48889
2 changed files with 38 additions and 0 deletions

View file

@ -4,6 +4,22 @@ import os
import configparser
class Config:
"""Provide configuration as object elements.
Example:
if the config file includes the lines::
[conf]
confi = 5
Then you config.confi is 5.
Configurations that should be ints are ints,
the other strings.
(Maybe including other datatypes like tuples later.)
"""
def __init__(self, path):
"""Create config object.
@ -13,6 +29,9 @@ class Config:
"""
config = configparser.ConfigParser()
config.read(path)
int_items = ("numberOfCards",)
for item in int_items:
setattr(self, item, config.getint("conf", item))
class playcard:

19
testConfig.py Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env python3
"""Test for the Config class.
Tests:
* if numberOfCards is 10
* nonexistingOption does not exist
"""
from chooseCards import Config
config = Config("config.cfg")
assert config.numberOfCards is 10
try:
config.nonexistingOption
except AttributeError:
pass # everything OK
else:
assert 1 == 0, "nonexistingOption should give error" # should not happen
print("Config tested. Is OK.")