Skip to content

Conversation

@jonasbardino
Copy link
Contributor

@jonasbardino jonasbardino commented Nov 1, 2025

Adds basic unit tests for additional mig/shared/fileio.py functions like:

  • read_file, read_file_lines, read_head_lines, read_tail_lines, write_file_lines
  • make_symlink, delete_symlink
  • touch, delete_file, get_file_size
  • makedirs_rec, remove_dir, remove_rec, check_empty_dir
  • move_file, move_rec, copy_file, copy_rec
  • check_read_access, check_write_access, check_readable, check_writable, check_readonly, check_readwritable
    reusing the existing structure.

Integrates PR #376 fixes so this PR should either replace the former or only be merged afterwards.

Includes a TODO to fix get_file_size to actually return result value on exception as it currently doesn't and therefore effectively returns None e.g. for missing paths.

Includes a TODO to fix a (possible py3 regression) bug in touch to make it work again for existing files and directories.

Includes tests to cover the corner-case bugs of the check access helpers registered in issue #378 when run outside the docker containers e.g. with make unittest rather than make test.

@jonasbardino jonasbardino self-assigned this Nov 1, 2025
@jonasbardino jonasbardino added the test-only Improvements or additions solely for better test coverage - without functionality changes label Nov 1, 2025
jonasbardino added a commit that referenced this pull request Nov 1, 2025
…helpers of

the `fileio.py` module as explained in issue #378 and covered by the unit tests
in PR #377.
…ollow up

to PR48. Minor comment clean up and line length adjustment from autopep8.
 1. `read_file`
 2. `read_file_lines`
 3. `get_file_size`
 4. `delete_file`
 5. `read_head_lines`
 6. `read_tail_lines`
 7. `make_symlink`
reusing the existing structure.

Includes a TODO to fix get_file_size to actually return result value on
exception as it currently doesn't and therefore effectively returns None.
1. `touch`
2. `remove_dir`
3. `remove_rec`
4. `move_file` and `move_rec`
5. `copy_file` and `copy_rec`
6. `check_empty_dir`
7. `makedirs_rec`

Discovered a corner-case bug in `touch` which renders it broken for existing
files and directories. So the corresponding tests are disabled and with TODO
markers to fix the bug and enable them.
Please note that we effectively run unit tests as uid 0 when using the
containerized setup, and that may yield rather surprising results when testing
file access, because super-users have access to everything despite what the
permissions indicate.

The added tests take uid 0 into account and will succeed, but we should really
eliminate these privileges when unit testing as they can easily cause a lot of
head-scratching.

The tests also uncovered a couple of additional corner case bugs in the access
checks, which don't show up with the uid 0 case but need to be addressed for
the general benefit. They have been registered in issue #378 for further work.
@jonasbardino jonasbardino force-pushed the add/improved-fileio-unit-test-coverage branch from 1ce6985 to 24f29dd Compare November 4, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test-only Improvements or additions solely for better test coverage - without functionality changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants