def test_permission_error(self): """Tests if permission denied is correctly handled.""" if sys.platform == 'win32': pytest.skip("Test not supported on Windows") filename = str( hashlib.sha256(str(time.time()).encode("utf-8")).hexdigest()) with open(filename, "w+", encoding='utf-8'): pass # Make it unreadable (mode 000) os.chmod(filename, not stat.S_IRWXU) with self.assertRaises(zhmc_prometheus_exporter.ImproperExit): zhmc_prometheus_exporter.parse_yaml_file(filename, 'test file') os.remove(filename)
def test_permission_error(self): """Tests if permission denied is correctly handled.""" filename = str( hashlib.sha1(str(time.time()).encode("utf-8")).hexdigest()) with open(filename, "w+"): pass # Make it unreadable (mode 000) os.chmod(filename, not stat.S_IRWXU) with self.assertRaises(PermissionError): (zhmc_prometheus_exporter.parse_yaml_file(filename)) os.remove(filename)
def test_normal_input(self): """Tests if some generic file is correctly parsed.""" # Get a SHA1 of Unixtime to create a filename that does not exist filename = str( hashlib.sha1(str(time.time()).encode("utf-8")).hexdigest()) with open(filename, "w+") as testfile: testfile.write("""metrics: hmc: 127.0.0.1 userid: user password: pwd """) expected_dict = { "metrics": { "hmc": "127.0.0.1", "userid": "user", "password": "******" } } self.assertEqual(zhmc_prometheus_exporter.parse_yaml_file(filename), expected_dict) os.remove(filename)
def test_not_found_error(self): """Tests if file not found is correctly handled.""" filename = str( hashlib.sha1(str(time.time()).encode("utf-8")).hexdigest()) with self.assertRaises(FileNotFoundError): zhmc_prometheus_exporter.parse_yaml_file(filename)