예제 #1
0
 def test_host_name_filter(self):
     """Make sure :func:`install()` integrates with :class:`~coloredlogs.HostNameFilter()`."""
     install(fmt='%(hostname)s')
     with CaptureOutput() as capturer:
         logging.info("A truly insignificant message ..")
         output = capturer.get_text()
         assert find_hostname() in output
예제 #2
0
 def test_host_name_filter(self):
     """Make sure :func:`install()` integrates with :class:`~coloredlogs.HostNameFilter()`."""
     install(fmt='%(hostname)s')
     with CaptureOutput() as capturer:
         logging.info("A truly insignificant message ..")
         output = capturer.get_text()
         assert find_hostname() in output
예제 #3
0
 def test_find_hostname(self):
     """Make sure :func:`~find_hostname()` works correctly."""
     assert find_hostname()
     # Create a temporary file as a placeholder for e.g. /etc/debian_chroot.
     fd, temporary_file = tempfile.mkstemp()
     try:
         with open(temporary_file, 'w') as handle:
             handle.write('first line\n')
             handle.write('second line\n')
         CHROOT_FILES.insert(0, temporary_file)
         # Make sure the chroot file is being read.
         assert find_hostname() == 'first line'
     finally:
         # Clean up.
         CHROOT_FILES.pop(0)
         os.unlink(temporary_file)
     # Test that unreadable chroot files don't break coloredlogs.
     try:
         CHROOT_FILES.insert(0, temporary_file)
         # Make sure that a usable value is still produced.
         assert find_hostname()
     finally:
         # Clean up.
         CHROOT_FILES.pop(0)
예제 #4
0
 def test_find_hostname(self):
     """Make sure :func:`~find_hostname()` works correctly."""
     assert find_hostname()
     # Create a temporary file as a placeholder for e.g. /etc/debian_chroot.
     fd, temporary_file = tempfile.mkstemp()
     try:
         with open(temporary_file, 'w') as handle:
             handle.write('first line\n')
             handle.write('second line\n')
         CHROOT_FILES.insert(0, temporary_file)
         # Make sure the chroot file is being read.
         assert find_hostname() == 'first line'
     finally:
         # Clean up.
         CHROOT_FILES.pop(0)
         os.unlink(temporary_file)
     # Test that unreadable chroot files don't break coloredlogs.
     try:
         CHROOT_FILES.insert(0, temporary_file)
         # Make sure that a usable value is still produced.
         assert find_hostname()
     finally:
         # Clean up.
         CHROOT_FILES.pop(0)