def test_passes_on_dissimilar_errors(self): class DeliberateError(Exception): """Deliberately induced error for testing.""" with ExpectedException(DeliberateError): with report_missing_config_dir(): raise DeliberateError("This exception propagates unchanged.")
def write_zone_file(cls, output_file, *parameters): """Write a zone file based on the zone file template. There is a subtlety with zone files: their filesystem timestamp must increase with every rewrite. Some filesystems (ext3?) only seem to support a resolution of one second, and so this method may set an unexpected modification time in order to maintain that property. """ if not isinstance(output_file, list): output_file = [output_file] for outfile in output_file: content = render_dns_template(cls.template_file_name, *parameters) with report_missing_config_dir(): incremental_write(content.encode("utf-8"), outfile, mode=0o644) pass
def test_succeeds_if_no_exceptions(self): with report_missing_config_dir(): pass # The real test is that we get here without error. pass
def test_passes_on_other_similar_errors(self): with ExpectedException(PermissionError): with report_missing_config_dir(): # OSError(EACCESS) is transmogrified, by Python itself, into # PermissionError. It's a subclass of OSError. raise OSError(errno.EACCES, "Deliberate error for testing.")
def test_specially_reports_missing_config_dir(self): with ExpectedException(DNSConfigDirectoryMissing): with report_missing_config_dir(): open(os.path.join(self.make_dir(), "nonexistent-file.txt"))