News for hackers. Stuff that matters.
Re:How many errors? by monochromatic on Monday September 07, 2015 @08:47PM (#10183693)
I'm not 100% sure what the intent of the code is, but it sounds like something that doesn't need a regex at all. Would

    'test' in x.lower()
work? Or maybe

    x[:4].lower() == 'test'
if you want it to be at the beginning.
Re:How many errors? by bobwaycott on Tuesday September 08, 2015 @04:42AM (#10184620)
They're ultimately trying to match files, directories, method names, and class names they assume to contain tests.

You could certainly check it with

    maybe.lower().startswith(test_string)
and

    maybe.lower().endswith(test_string)
to accomplish part of what appears to be originally desired. But it's just a part.

Python expects explicit behavior, and nose would do well to improve itself by providing interfaces for detecting, registering, and running tests by file, directory, method, or class in clear, provably correct ways.

It'd be far more reliable to start with a provable interface to `os.walk()` through a directory/tree, grab the Python files, load & test the classes to ensure they are of the desired type, and execute them--assuming here the tests are written via classes and not just modules full of random methods you hope include the word 'test', or you hope are actually meant for nose tests, and not something application-specific. Or perhaps offer a decorator for standalone methods when that is a developer's chosen pattern. Or provide a single default directory that is searched, and a flag that allows a dev to override it. Same for files--provide a sane default filename that is searched via `os.walk()` for collecting tests, with a flag to specify a different filename where desired.

Slower, sure. But at least not completely fucked up and wrong. Once they can prove it works 100% of the time, then they can go about digging into making it better and faster. But for fuck's sake, start with the simplest working solution and build from there. Especially when the problem has existed for more than 5 years.

EDIT: Oops, misplaced the lowers. It's that time of the night when I shouldn't be writing code.

Re:How many errors? by eridius on Tuesday September 08, 2015 @12:15AM (#10184095)
No, because the goal here isn't just to match it at the beginning, it's also to match it after a non-word character. I don't know what the inputs look like, but the regex was clearly intended to match things like "foo.testMe", "bar-test", "baz/Test.ext", etc.
Re:How many errors? by lgas on Monday September 07, 2015 @09:25PM (#10183788)

    x.startswith("test")
Re:How many errors? by monochromatic on Monday September 07, 2015 @09:43PM (#10183828)
Even better, forgot about that one. Still needs a lower() though.
Re:How many errors? by dualbus on Monday September 07, 2015 @09:16PM (#10183769)
x[:4].lower() = 'test' ?
Re:How many errors? by monochromatic on Monday September 07, 2015 @09:47PM (#10183836)
Whoops, forgot the double equal. As penance, I'll quote some Steve Yegge.

> Error Prone == Evil

> Although this concept is obvious to 99.999% of the general population, it's only accepted by 2% of computer programmers. The remaining 98% subscribe to a competing philosophy, namely: "Error Prone = Manly". Never mind that they just assigned "Manly" to the variable "Error Prone", and the expression always returns true; that happens to be the correct value in this case, so it's an acceptable hack.

Re:How many errors? by icebraining on Tuesday September 08, 2015 @03:48AM (#10184473)
Except it'd just error out with "can't assign to function call". You also can't assign in if/while (they expect an expression, while assignment makes it a statement).

So, all-in-all, in Python it's not really error prone unless you never run the code at all.

Re:How many errors? by monochromatic on Thursday September 10, 2015 @02:13PM (#10199593)
In other news, sometimes jokes are not literally true.