def _load_fixtures(self, filenames, models_package=''): """Pre-load the fixtures. :param list or str filenames: files that hold the fixture data :param str models_package: """ if isinstance(filenames, _compat.string_types): globbed_filenames = glob(filenames) else: globbed_filenames = list( chain.from_iterable(glob(f) for f in filenames) ) if not globbed_filenames: raise IOError('File "%s" not found' % filenames) if len(globbed_filenames) == 1: content = load_file(filenames, self.use_unicode) else: content = {} for filename in globbed_filenames: namespace = self._get_namespace_from_filename(filename) content[namespace] = { "objects": load_file(filename, self.use_unicode) } 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
def _load_fixtures(self, filenames, models_package=''): """Pre-load the fixtures. :param list or str filenames: files that hold the fixture data :param str models_package: """ if isinstance(filenames, _compat.string_types): globbed_filenames = glob(filenames) else: globbed_filenames = list( chain.from_iterable(glob(f) for f in filenames) ) if not globbed_filenames: raise IOError('File "%s" not found' % filenames) if len(globbed_filenames) == 1: content = load_file(globbed_filenames[0], self.use_unicode) else: content = {} for filename in globbed_filenames: namespace = self._get_namespace_from_filename(filename) content[namespace] = { "objects": load_file(filename, self.use_unicode) } 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
def _load_fixtures(self, filenames): """Pre-load the fixtures. :param list or str filenames: files that hold the fixture data """ if isinstance(filenames, _compat.string_types): globbed_filenames = glob(filenames) else: globbed_filenames = list( chain.from_iterable(glob(f) for f in filenames) ) if len(globbed_filenames) == 1: content = load_file(filenames, self.use_unicode) else: content = {} for filename in globbed_filenames: namespace = self._get_namespace_from_filename(filename) content[namespace] = { "objects": load_file(filename, self.use_unicode) } fixtures = {} for k, v in _compat.iteritems(content): if "objects" in v: # It's a collection of fictures. fixtures[k] = self._handle_collection( namespace=k, definition=v, objects=v["objects"], ) # Named fixtures else: if "id" in v: # Renaming id because it's a Python builtin function v["id_"] = v["id"] del v["id"] fixtures[k] = Fixture(key=k, fixture_manager=self, **v) d = DepGraph() for fixture in fixtures.values(): for dependency, _ in fixture.extract_relationships(): d.add_edge(dependency, fixture.key) # This does nothing except raise an error if there's a cycle d.topo_sort() return fixtures, d
def setUp(self): # preserve the original constructor for strings self.str_constructor = SafeConstructor.yaml_constructors[ u'tag:yaml.org,2002:str'] self.yaml = file_format.load_file( './charlatan/tests/data/unicode.yaml', use_unicode=True, )
def setUp(self): with mock.patch('charlatan.file_format.datetime') as dt_mock: self.current_time = datetime.datetime.utcnow() dt_mock.datetime.utcnow.return_value = self.current_time self.yaml = file_format.load_file( './charlatan/tests/data/special_tags.yaml' )
def setUp(self): # preserve the original constructor for strings self.str_constructor = SafeConstructor.yaml_constructors[ u'tag:yaml.org,2002:str' ] self.yaml = file_format.load_file( './charlatan/tests/data/strings.yaml', use_unicode=True, )
def test_non_yaml_file(): """Verify that we can't open a non-YAML file.""" with pytest.raises(ValueError): file_format.load_file("./charlatan/tests/data/test.json")
def setUp(self): self.current_time = datetime.datetime.utcnow().replace( tzinfo=pytz.utc) self.yaml = file_format.load_file( './charlatan/tests/data/special_tags.yaml' )
def setUp(self): self.yaml = file_format.load_file( './charlatan/tests/data/strings.yaml', )