@@ -37,16 +37,14 @@ class TestCrosECPWM(unittest.TestCase):
fd = open("/sys/class/backlight/backlight/brightness", "w")
fd.write(str(brightness))
fd.close()
- fd = open("/sys/kernel/debug/pwm", "r")
- line = fd.readline()
- while line:
- if "backlight" in line:
- start = line.find("duty") + 6
- self.assertNotEqual(start, 5)
- end = start + line[start:].find(" ")
- self.assertNotEqual(start, end)
- duty = int(line[start:end])
- self.assertNotEqual(duty, 0)
- break
- line = fd.readline()
- fd.close()
+
+ with open("/sys/kernel/debug/pwm", "r") as fh:
+ for line in fh:
+ if "backlight" in line:
+ start = line.find("duty") + 6
+ self.assertNotEqual(start, 5)
+ end = start + line[start:].find(" ")
+ self.assertNotEqual(start, end)
+ duty = int(line[start:end])
+ self.assertNotEqual(duty, 0)
+ break