English 中文(简体)
如何处理经测试的个案名称,分几个线。
原标题:Python how to handle test case names split over several lines

我在使用这一格式的测试的基础上,从数据库中发现了新的测试案例:

TEST_F(CLASSNAME, TESTCASENAME)

现在有这样的一个试验案例,即自动格式似乎如此:

TEST_F(

CLASSNAME,

TESTCASENAME)

Before I get each piece of information based on the format TEST_F(CLASSNAME, TESTCASENAME) as follows:

    print("Looking for new tests")
    for root, dirs, files in os.walk(cpp_tests_dir_path):
        for file in files:
            with open(os.path.join(root, file), encoding="utf8", errors= ignore ) as f:
                for line in f:
                    if "TEST_F(" in line:
                        data = line.split("TEST_F(")[1]
                        c_class = data.split(",")[0]
                        c_test_case = data.split(",")[1].split(")")[0].strip().split()[0]

但是,如果有一个像我前面提到的那样具有如此长的名称和格式的试验案例。 已被分离成多个线

TEST_F(

CLASSNAME,

TESTCASENAME)

我如何调整逻辑,以获得每项价值的价值?

更新额外信息,测试点命名应如下:

TEST_F(CMilestoneChallengeModelTest, SetChallenges_ListenerNotRegistered_ListenerIsNotNotified)

问题1

TEST_F(
    CDailyWinTest,
GIVEN_DailyWinRevamped_WHEN_PlayerWinGameinDay_AND_DoesntCollectAllStickers_THEN_CelebrationPopupAppear) 

Update the code base on the comment

    print("Looking for new tests")
    for root, dirs, files in os.walk(cpp_tests_dir_path):
        for file in files:
            with open(os.path.join(root, file), encoding="utf8", errors= ignore ) as f:
                content = f.read()
                test_cases = re.findall(r TEST_F(s*w*s*,s*w*s*) , content)
                for line in test_cases:
                    if "TEST_F(" in line:
                        data = line.split("TEST_F(")[1]
                        c_class = data.split(",")[0]
                        c_test_case = data.split(",")[1].split(")")[0].strip().split()[0]
问题回答

这正是你需要经常表达的。 我不知道你的测试案例是什么样子,但如果是用信件和数字来判断,没有空间,你就能够利用这种模式来找到测试案例。

<编码> TEST_F(s*w*s*,s*w*s*

您可以照此重写:

for root, dirs, files in os.walk(cpp_tests_dir_path):
    for file in files:
        with open(os.path.join(root, file), encoding="utf8", errors= ignore ) as f:
            content = f.read()
            test_cases = re.findall(r TEST_F(s*w*s*,s*w*s*) ,content)
            print(test_cases)

现在,如果你的文件内容如此的话:

TEST_F(CLASSNAME1, TESTCASENAME1)
TEST_F(CLASSNAME2, TESTCASENAME2)
TEST_F(
    CLASSNAME3,
     TESTCASENAME
    )
                

页: 1

[ TEST_F(CLASSNAME1, TESTCASENAME1) ,  TEST_F(CLASSNAME2, TESTCASENAME2) ,  TEST_F(
    CLASSNAME3,
     TESTCASENAME
    ) ]

在这一步骤中,你在一份清单中列出了所有测试案例,请您从名单上获得分类名称和验证名称。

假设这几类名称和测试名称是信件和强调的,你可以更新如下的代码:

print("Looking for new tests")
for root, dirs, files in os.walk(cpp_tests_dir_path):
    for file in files:
        with open(os.path.join(root, file), encoding="utf8", errors= ignore ) as f:
            content = f.read()
            test_cases = re.findall(r TEST_F(s*w*s*,s*w*s*) , content)
            for test_case in test_cases:
                cleaned = re.sub(r [s] ,  ,test_case) # removing white spaces
                _, c_class, data = re.findall( w+ ,cleaned)
                print(_ , c_class, data) # checking results

您可将类别名称和测试类别列入捕获组,以便re.findall。 可在<<><<>t>>>>t>>> 栏目中将其输出到可变数中:

for c_class, c_test_case in re.findall(r TEST_F(s*(w*)s*,s*(w*)s*) , content):
    print(c_class, c_test_case)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签