-
Notifications
You must be signed in to change notification settings - Fork 46
Custom methods must be protected #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
fa9d4d2
655df9d
62fa5db
d440bad
fbdb45e
3c27f7b
9dddb9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ def test_conanfile(self): | |
self.assertIn("ERROR: [CONAN CENTER INDEX URL (KB-H027)] The attribute 'url' should " \ | ||
"point to: https://github.com/conan-io/conan-center-index", output) | ||
self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) | ||
self.assertIn("[CUSTOM METHODS (KB-H036)] OK", output) | ||
self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] OK", output) | ||
self.assertIn("[SINGLE REQUIRES (KB-H055)] OK", output) | ||
|
||
|
@@ -141,6 +142,7 @@ def test_conanfile_header_only(self): | |
"recipe", output) | ||
self.assertIn("[META LINES (KB-H025)] OK", output) | ||
self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) | ||
self.assertIn("[CUSTOM METHODS (KB-H036)] OK", output) | ||
self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] OK", output) | ||
|
||
def test_conanfile_header_only_with_settings(self): | ||
|
@@ -162,6 +164,7 @@ def test_conanfile_header_only_with_settings(self): | |
"recipe", output) | ||
self.assertIn("[META LINES (KB-H025)] OK", output) | ||
self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) | ||
self.assertIn("[CUSTOM METHODS (KB-H036)] OK", output) | ||
self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] OK", output) | ||
|
||
def test_conanfile_settings_clear_with_settings(self): | ||
|
@@ -204,6 +207,7 @@ def test_conanfile_installer(self): | |
"recipe", output) | ||
self.assertIn("[META LINES (KB-H025)] OK", output) | ||
self.assertIn("[CMAKE MINIMUM VERSION (KB-H028)] OK", output) | ||
self.assertIn("[CUSTOM METHODS (KB-H036)] OK", output) | ||
|
||
def test_shebang(self): | ||
conanfile = textwrap.dedent("""\ | ||
|
@@ -604,6 +608,41 @@ def system_requirements(self): | |
self.assertIn("[SYSTEM REQUIREMENTS (KB-H032)] 'libusb' is part of the allowlist.", output) | ||
self.assertNotIn("ERROR: [SYSTEM REQUIREMENTS (KB-H032)]", output) | ||
|
||
def test_invalid_recipe_methods(self): | ||
conanfile = textwrap.dedent("""\ | ||
from conans import ConanFile | ||
class AConan(ConanFile): | ||
url = "fake_url.com" | ||
license = "fake_license" | ||
description = "whatever" | ||
homepage = "homepage.com" | ||
topics = ("fake_topic", "another_fake_topic") | ||
|
||
def configure(self): | ||
self.output.info("ok") | ||
|
||
def barbarian(self): | ||
self.output.info("Conan") | ||
|
||
def __my_own_method(self): | ||
self.output.info("foobar") | ||
|
||
def __my_private_method(self): | ||
self.output.info("foobar") | ||
|
||
def __abs__(self): | ||
return self.version | ||
|
||
def _baz(self): | ||
self.output.info("qux") | ||
|
||
""") | ||
tools.save('conanfile.py', content=conanfile) | ||
output = self.conan(['create', '.', 'name/version@user/test']) | ||
self.assertIn("ERROR: [CUSTOM METHODS (KB-H036)] Custom methods must be declared as " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be too strict, as we may define some magic methods ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but it's the exception you know. It sounds like cccl and other few recipes. We know that is not a regular case, but new contributors can use private instead of protected when writing a recipe, for instance. |
||
"protected. The follow methods are invalid: '__my_own_method', " | ||
"'__my_private_method', 'barbarian'", output) | ||
|
||
def test_imports_not_allowed(self): | ||
conanfile_tp = textwrap.dedent("""\ | ||
from conans import ConanFile, tools | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, you query valid attrs and current attrs, why query invalid attrs with different method?
isn't result the same as
current_attrs - valid_attrs
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private methods are not filtered by
dir
method. e.g.def __foo(self):