2# +==== BEGIN rotary_logger =================+
4# ..........####...####..........
5# ......###.....#.#########......
6# ....##........#.###########....
7# ...#..........#.############...
8# ...#..........#.#####.######...
9# ..#.....##....#.###..#...####..
10# .#.....#.##...#.##..##########.
11# #.....##########....##...######
12# #.....#...##..#.##..####.######
13# .#...##....##.#.##..###..#####.
14# ..#.##......#.#.####...######..
15# ..#...........#.#############..
16# ..#...........#.#############..
17# ...##.........#.############...
18# ......#.......#.#########......
19# .......#......#.########.......
20# .........#####...#####.........
22# PROJECT: rotary_logger
23# FILE: test_file_instance.py
24# CREATION DATE: 01-11-2025
25# LAST Modified: 3:42:18 04-03-2026
27# A module that provides a universal python light on iops way of logging to files your program execution.
29# COPYRIGHT: (c) Asperguide
30# PURPOSE: This is the set of tests in charge of making sure the file_instance class works as expected.
32# +==== END rotary_logger =================+
34from pathlib
import Path
40 logs = list(root.rglob(
'*.log'))
49 root = tmp_path /
'logs.log'
52 fi.write(
'hello file_instance\n')
55 assert logfile
is not None,
'No .log file created by FileInstance'
56 content = logfile.read_text(encoding=fi.get_encoding())
57 assert 'hello file_instance' in content
61 if fi
and fi.get_filepath():
62 fp = fi.get_filepath()
63 if fp
and getattr(fp,
'descriptor',
None):
75 assert fi.get_encoding()
is not None
76 assert fi.get_flush_size() > 0
77 assert fi.get_max_size() > 0
81 """When log_to_file=False, no file should be created even after writing."""
82 log_path = tmp_path /
'should_not_exist.log'
84 fi.write(
'this should not be written to disk\n')
86 assert not log_path.exists(),
"File must not be created when log_to_file=False"
90 """copy() should return a new instance with identical configuration but no shared state."""
92 fi.set_merge_stdin(
True)
95 assert copy.get_encoding() ==
'utf-16'
96 assert copy.get_merged()
is False
97 assert copy.get_merge_stdin()
is True
99 copy.set_encoding(
'utf-8')
100 assert fi.get_encoding() ==
'utf-16'
104 """update() should copy all configuration fields from the source instance."""
105 src =
FileInstance(
None, encoding=
'latin-1', merged=
False)
106 src.set_merge_stdin(
True)
109 assert dst.get_encoding() ==
'latin-1'
110 assert dst.get_merged()
is False
111 assert dst.get_merge_stdin()
is True
115 """set_merge_stdin / get_merge_stdin round-trip should be consistent."""
117 assert fi.get_merge_stdin()
is False
118 fi.set_merge_stdin(
True)
119 assert fi.get_merge_stdin()
is True
120 fi.set_merge_stdin(
False)
121 assert fi.get_merge_stdin()
is False
None test_file_instance_log_to_file_false_suppresses_write(Path tmp_path)
None test_file_instance_defaults(Path tmp_path)
_find_log_file(Path root)
None test_file_instance_copy_is_independent(Path tmp_path)
None test_file_instance_update_copies_config(Path tmp_path)
None test_file_instance_set_get_merge_stdin()
None test_file_instance_write_and_flush(Path tmp_path)