4 ms·
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
by monochromatic 11y ago
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.
- dualbus 11y agox[:4].lower() = 'test' ?
- monochromatic 11y agoWhoops, 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.
- icebraining 11y agoExcept 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.
- monochromatic 11y agoIn other news, sometimes jokes are not literally true.
- lgas 11y agox.startswith("test")
- monochromatic 11y agoEven better, forgot about that one. Still needs a lower() though.
- eridius 11y agoNo, 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.
- bobwaycott 11y agoThey'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.