-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes add_source_file(s) method raise exception when no files match
- Loading branch information
Showing
3 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2015, Lars Asplund [email protected] | ||
# Copyright (c) 2014-2016, Lars Asplund [email protected] | ||
|
||
""" | ||
Functionality to represent and operate on a HDL code project | ||
|
@@ -76,6 +76,9 @@ def add_source_file(self, file_name, library_name, file_type='vhdl', include_dir | |
""" | ||
Add a file_name as a source file in library_name with file_type | ||
""" | ||
if not ostools.file_exists(file_name): | ||
raise ValueError("File %r does not exist" % file_name) | ||
|
||
LOGGER.info('Adding source file %s to library %s', file_name, library_name) | ||
self._validate_library_name(library_name) | ||
library = self._libraries[library_name] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2015, Lars Asplund [email protected] | ||
# Copyright (c) 2014-2016, Lars Asplund [email protected] | ||
|
||
""" | ||
Acceptance test of the VUnit public interface class | ||
|
@@ -203,6 +203,19 @@ def test_can_add_non_ascii_encoded_files(self): | |
lib.add_source_files(join(dirname(__file__), 'test_ui_encoding.vhd')) | ||
lib.entity("encoding") # Fill raise exception of not found | ||
|
||
def test_exception_on_adding_zero_files(self): | ||
ui = self._create_ui() | ||
lib = ui.library("lib") | ||
self.assertRaisesRegexp(ValueError, "Pattern.*missing1.vhd.*", | ||
lib.add_source_files, join(dirname(__file__), 'missing1.vhd')) | ||
self.assertRaisesRegexp(ValueError, "File.*missing2.vhd.*", | ||
lib.add_source_file, join(dirname(__file__), 'missing2.vhd')) | ||
|
||
def test_no_exception_on_adding_zero_files_when_allowed(self): | ||
ui = self._create_ui() | ||
lib = ui.library("lib") | ||
lib.add_source_files(join(dirname(__file__), 'missing.vhd'), allow_empty=True) | ||
|
||
def _test_pre_config_helper(self, retval, test_not_entity=False): | ||
""" | ||
Helper method to test pre_config where the pre config can return different values | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2014-2015, Lars Asplund [email protected] | ||
# Copyright (c) 2014-2016, Lars Asplund [email protected] | ||
|
||
""" | ||
The main public Python interface of VUnit. | ||
|
@@ -247,13 +247,20 @@ def disable_ieee_warnings(self): | |
""" | ||
self._configuration.disable_ieee_warnings(scope=create_scope()) | ||
|
||
def add_source_files(self, pattern, library_name, preprocessors=None, include_dirs=None): | ||
def add_source_files(self, # pylint: disable=too-many-arguments | ||
pattern, library_name, preprocessors=None, include_dirs=None, allow_empty=False): | ||
""" | ||
Add source files matching wildcard pattern to library | ||
""" | ||
file_names = glob(pattern) | ||
|
||
if (not allow_empty) and len(file_names) == 0: | ||
raise ValueError(("Pattern %r did not match any file. " | ||
"Use allow_empty=True to avoid exception,") % pattern) | ||
|
||
return FileSetFacade(source_files=[ | ||
self.add_source_file(file_name, library_name, preprocessors, include_dirs) | ||
for file_name in glob(pattern)]) | ||
for file_name in file_names]) | ||
|
||
def add_source_file(self, file_name, library_name, preprocessors=None, include_dirs=None): | ||
""" | ||
|
@@ -559,8 +566,12 @@ def disable_ieee_warnings(self): | |
""" | ||
self._configuration.disable_ieee_warnings(scope=self._scope) | ||
|
||
def add_source_files(self, pattern, preprocessors=None): | ||
return self._parent.add_source_files(pattern, self._library_name, preprocessors) | ||
def add_source_files(self, pattern, preprocessors=None, allow_empty=False): | ||
return self._parent.add_source_files(pattern, self._library_name, preprocessors, | ||
allow_empty=allow_empty) | ||
|
||
def add_source_file(self, pattern, preprocessors=None): | ||
return self._parent.add_source_file(pattern, self._library_name, preprocessors) | ||
|
||
def package(self, package_name): | ||
""" | ||
|