There is a shell command, I am trying to convert the logic into python. But I don't know what to do, I need some help with that.
shell command is this :
cd ../../../tests/src/main/java
ls
grep -R "@Test" -A 1 | grep void | while read LINE
do
CLASS=`echo $LINE | cut -f1 -d"." | sed s/"\/"/"\."/g`
TEST_CASE=`echo $LINE | sed s/"void "/
The logic is inside a directory, reads the filename one by one, includes all sub-folders, then lists the file matches.
grep -R "@Test" -A 1 | grep void translates to reading the file line by line. If the line matches @Test, read the next line, then do if 'void' in nextline
I tried something like follows, but I don't know the sed command exactly doing and how to convert it into python script. for example
CLASS=`echo $LINE | cut -f1 -d"." | sed s/"\/"/"\."/g`
TEST_CASE=`echo $LINE | sed s/"void "/
For retrieve the data send to parameter CLASS and TEST_CASE , I did the cut but I don't know how to do the sed
for root, dirs, files in os.walk(../../../tests/src/main/java):
for file in files:
with open(os.path.join(root, file), encoding="utf8", errors='ignore') as f:
for line in f:
nextLine = next(f)
if "@Test" in line:
if "void" in nextLine:
CLASS = nextLine.split(",")[0] // How to apply the sed here?
TEST_CASE = nextLine // How to apply the sed here?
Any help will be much appreciated