Re: [openstack-dev] [Hacking] unit test code is too less

2014-01-23 Thread ZhiQiang Fan
understand, thank you very much


On Thu, Jan 23, 2014 at 3:45 PM, Yuriy Taraday yorik@gmail.com wrote:

 Hello.


 On Thu, Jan 23, 2014 at 6:47 AM, ZhiQiang Fan aji.zq...@gmail.comwrote:

 I noticed that in openstack-dev/hacking project, there is very little
 test code, is there any particular reason why it is in such situation?


 Yes, there is. Every rule have a docstring that not only provides examples
 of good and bad code but also is run as a doctest here:
 https://github.com/openstack-dev/hacking/blob/master/hacking/tests/test_doctest.py


 https://github.com/openstack-dev/hacking/blob/master/hacking/core.py#L345
  it cannot detect

 \bprint$
 \bprint xxx, (\s+


 I'm not sure how can it not detect the second one since the regular
 expression used there to detect bad strings is  \bprint\s+[^\(] and it
 catches print xxx, ( string.
 The first one is a good catch though.

 If I want to improve this rule, how can I verify that my change is good?


 Just change that regular expression as is needed and add a line to the
 docstring like these:
 Okay: print()
 H233: print

 Happy coding!

 --

 Kind regards, Yuriy.

 ___
 OpenStack-dev mailing list
 OpenStack-dev@lists.openstack.org
 http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev




-- 
blog: zqfan.github.com
git: github.com/zqfan
___
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] [Hacking] unit test code is too less

2014-01-23 Thread Dirk Müller
Hi Zhi Qiang,

 for i.e. the hacking rule h233 in hacking looks not so robust,
 https://github.com/openstack-dev/hacking/blob/master/hacking/core.py#L345
 it cannot detect

 \bprint$
 \bprint xxx, (\s+

It currently detects both as a violation of the rule, which is IMHO
correct. Please note that the behavior of

  print

depends on if its an operator (then it prints a newline) and a
function (then it does nothing)


Greetings,
Dirk

___
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] [Hacking] unit test code is too less

2014-01-23 Thread ZhiQiang Fan
Hi, Dirk

If a line just with single print (which means a function name) does
nothing, I think it should be removed,

print$ cannot be detected by  \bprint\s+[^\(]

 import re
 print re.search(r\bprint\s+[^\(], print)
None
 print re.search(r\bprint(?:$|\s+[^\(]), print)
_sre.SRE_Match object at 0xb6c2bfa8


On Thu, Jan 23, 2014 at 7:06 PM, Dirk Müller d...@dmllr.de wrote:

 Hi Zhi Qiang,

  for i.e. the hacking rule h233 in hacking looks not so robust,
 
 https://github.com/openstack-dev/hacking/blob/master/hacking/core.py#L345
  it cannot detect
 
  \bprint$
  \bprint xxx, (\s+

 It currently detects both as a violation of the rule, which is IMHO
 correct. Please note that the behavior of

   print

 depends on if its an operator (then it prints a newline) and a
 function (then it does nothing)


 Greetings,
 Dirk

 ___
 OpenStack-dev mailing list
 OpenStack-dev@lists.openstack.org
 http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev




-- 
blog: zqfan.github.com
git: github.com/zqfan
___
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] [Hacking] unit test code is too less

2014-01-22 Thread Yuriy Taraday
Hello.


On Thu, Jan 23, 2014 at 6:47 AM, ZhiQiang Fan aji.zq...@gmail.com wrote:

 I noticed that in openstack-dev/hacking project, there is very little test
 code, is there any particular reason why it is in such situation?


Yes, there is. Every rule have a docstring that not only provides examples
of good and bad code but also is run as a doctest here:
https://github.com/openstack-dev/hacking/blob/master/hacking/tests/test_doctest.py


 https://github.com/openstack-dev/hacking/blob/master/hacking/core.py#L345
  it cannot detect

 \bprint$
 \bprint xxx, (\s+


I'm not sure how can it not detect the second one since the regular
expression used there to detect bad strings is  \bprint\s+[^\(] and it
catches print xxx, ( string.
The first one is a good catch though.

If I want to improve this rule, how can I verify that my change is good?


Just change that regular expression as is needed and add a line to the
docstring like these:
Okay: print()
H233: print

Happy coding!

-- 

Kind regards, Yuriy.
___
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev