Skip to content

Commit

Permalink
Merge pull request #61 from samstav/copyable-config
Browse files Browse the repository at this point in the history
a copyable Config object for python 3
  • Loading branch information
ziadsawalha committed Jul 10, 2015
2 parents 4c1e5ca + 40207f4 commit f02dce9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions simpl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ def __len__(self):

def __getattr__(self, attr):
"""Get attribute."""
# protection from infinite recursion when __init__
# is skipped during object creation (probably copy.copy)
if attr == '_values':
raise AttributeError()
if attr in self._values:
return self._values[attr]
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import print_function

import argparse
import copy
import errno
import os
import string
Expand Down Expand Up @@ -52,6 +53,15 @@ def get_tempfile(self, *args, **kwargs):
self.addCleanup(fp.close)
return fp

def test_copies(self):
cfg = config.Config(options=[
config.Option('--one', default=1),
config.Option('--a', default='a'),
config.Option('--none'),
])
another = copy.copy(cfg)
self.assertEqual(cfg, another)

def test_instantiation(self):
empty = config.Config(options=[])
self.assertIsInstance(empty, config.Config)
Expand Down

0 comments on commit f02dce9

Please sign in to comment.