测试SD卡直到失败Python程序

时间:2014-12-24 22:11:15

标签: python automated-tests sd-card

在这里需要一些帮助。

我一直在努力想出一个简单的(ish)计划,该计划将采取以下措施:

https://docs.google.com/document/d/1COBL4P6vqf3aVDm4OTJJcq-VDQ8f0TGVwvifJrpqPpE/edit?usp=sharing

不幸的是,我是一个完整的编程新手,我所做的最多的是一个BASIC程序,所以无论如何这是我到目前为止所有:

import filecmp
import os
import shutil
count = 0
while (count < 2):
    if os.listdir ("E:\\Test") ==[]:
        shutil.copy2("\\Users\Andrew\Desktop\Test.txt","E:\Test\Test.txt")
        filecmp.cmp("\\Users\Andrew\Desktop\Test.txt","E:\Test\Test.txt")
        count = count + 1
        break
else:
    shutil.rmtree("E:\\Test")
    os.mkdir("E:\\Test")

我没有使用While循环运行,但现在我完全陷入困境,它只是无限循环。任何帮助都会非常感谢!

1 个答案:

答案 0 :(得分:0)

对于那些感兴趣的人来说,这就是完成的程序的样子。

import filecmp
import os
import shutil
from datetime import datetime
#Imported all of the neccessary items for running the script
count = 0
read = 0
write = 0
copys = 0
fail = 0
delete = 0
data = shutil.disk_usage("E:\\")
free = (data[2])
with open ("\\Users\\Andrew\\Desktop\\SD Card Testing\\Test.txt","wb") as fout:
    fout.write(os.urandom(int(free)))
file = os.path.getsize("\\Users\\Andrew\\Desktop\\SD Card Testing\\Test.txt")
start = datetime.now()
while (fail == 0):
#While the fail count is == 0 then do:
    if os.listdir ("E:\\Test") ==[]:
        read = read + 1
#Check if the Dir is empty
        shutil.copy2("\\Users\\Andrew\\Desktop\\SD Card Testing\\Test.txt","E:\Test\Test.txt")
        copys = copys + 1
        write = write + 1
        print ((file*copys)/(1048576*1024),"GB")
        if filecmp.cmp("\\Users\\Andrew\\Desktop\\SD Card Testing\\Test.txt","E:\Test\Test.txt",shallow=False) == True:
            print(filecmp.cmp("\\Users\\Andrew\\Desktop\\SD Card Testing\\Test.txt","E:\Test\Test.txt",shallow=False))
            read = read + 2
#If the result of the file check is true print
        else:
            fail = fail + 1
            print ("Fail:",fail)
#If the result of the file check is false fail and break
    else:
        shutil.rmtree("E:\\Test")
        delete = delete + 1
        os.mkdir("E:\\Test")
        write = write + 2
        print ("Deletes:",delete)
#If the folder is not empty then remove it and replace
    count = count + 1
    print (count)
    end = datetime.now()
    print ("Duration: {}".format(end-start))
#When the loop breaks print the number of read/writes
print ("Read:",read)
print ("Write:",write)

我确信人们可以提供有关改进的建议,但我目前有两套SD卡测试,大约2.5 TB写入256 mB分区。