Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #42 from uber/yl-fix-empty-fixture-file
Browse files Browse the repository at this point in the history
make FixturesManager work with empty fixture file
  • Loading branch information
charlax committed Mar 3, 2015
2 parents 5526dda + f3ac9f1 commit d0e25ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
51 changes: 26 additions & 25 deletions charlatan/fixtures_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,32 @@ def _load_fixtures(self, filenames, models_package=''):
"objects": load_file(filename, self.use_unicode)
}

for k, v in _compat.iteritems(content):

if "objects" in v:
# It's a collection of fictures.
collection = self._handle_collection(
namespace=k,
definition=v,
objects=v["objects"],
models_package=models_package,
)
self.collection.add(k, collection)

# Named fixtures
else:
if "id" in v:
# Renaming id because it's a Python builtin function
v["id_"] = v["id"]
del v["id"]

fixture = Fixture(
key=k,
fixture_manager=self,
models_package=models_package,
**v)
self.collection.add(k, fixture)
if content:
for k, v in _compat.iteritems(content):

if "objects" in v:
# It's a collection of fictures.
collection = self._handle_collection(
namespace=k,
definition=v,
objects=v["objects"],
models_package=models_package,
)
self.collection.add(k, collection)

# Named fixtures
else:
if "id" in v:
# Renaming id because it's a Python builtin function
v["id_"] = v["id"]
del v["id"]

fixture = Fixture(
key=k,
fixture_manager=self,
models_package=models_package,
**v)
self.collection.add(k, fixture)

graph = self._check_cycle(self.collection)
return graph
Expand Down
Empty file added charlatan/tests/data/empty.yaml
Empty file.
6 changes: 6 additions & 0 deletions charlatan/tests/test_fixtures_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def test_load_two_files(self):
'./charlatan/tests/data/simple.yaml')
assert 'simple_dict' in manager.keys()

def test_load_empty_file(self):
"""Verify we can load a emtpy file."""
manager = FixturesManager()
manager.load('./charlatan/tests/data/empty.yaml')
self.assertEqual(list(manager.keys()), [])

def test_install_fixture(self):
"""install_fixture should return the fixture."""
manager = FixturesManager()
Expand Down

0 comments on commit d0e25ff

Please sign in to comment.