Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_readWriteCrontab fails when crontab is an empty file #1181

Closed
willemw12 opened this issue Jul 21, 2021 · 3 comments
Closed

test_readWriteCrontab fails when crontab is an empty file #1181

willemw12 opened this issue Jul 21, 2021 · 3 comments

Comments

@willemw12
Copy link

Test test_readWriteCrontab fails when crontab is an empty file.

$ crontab -e

Save an empty crontab.

$ crontab -l | wc -l
0

$ LC_ALL=en_US.UTF-8 make common test-v
...
test_readWriteCrontab (test.test_tools.TestTools) ... FAIL
...
Stdout:
DEBUG: [common/tools.py:1237 readCrontab] Read 1 lines from users crontab
DEBUG: [common/tools.py:1274 writeCrontab] Wrote 2 lines to users crontab
DEBUG: [common/tools.py:1237 readCrontab] Read 1 lines from users crontab
@aryoda
Copy link
Contributor

aryoda commented Sep 6, 2022

Congrats, perfect issue report with excellent minimal reproducible example :-)

I could reproduce the test failure on HEAD and Ubuntu 20.04 with Python 3.8.10 via LC_ALL=en_US.UTF-8; make test-v:

FAIL: test_readWriteCrontab (test.test_tools.TestTools)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/XXX/dev/backintime/common/test/test_tools.py", line 556, in test_readWriteCrontab
    self.assertEqual(len(newCrontab), len(oldCrontab) + 1)
AssertionError: 1 != 2

Stdout:
DEBUG: [common/tools.py:1237 readCrontab] Read 1 lines from users crontab
DEBUG: [common/tools.py:1274 writeCrontab] Wrote 2 lines to users crontab
DEBUG: [common/tools.py:1237 readCrontab] Read 1 lines from users crontab

Would be great if a developer here raises the hand to fix this (I have no more time this week), since it is so easy to reproduce...

@aryoda
Copy link
Contributor

aryoda commented Sep 8, 2022

Diagnoses:

This code line creates a list of lines from the file content using the new line char (\n) to split the lines:

https://github.com/bit-team/backintime/blob/master/common/tools.py#L1236

If the crontab file is empty it returns a list of length 1 (sic!) with an empty string instead of an empty list:

crontab = {list: 1}['']

Instead an empty file should return a an empty list of length 0:

[]

I think the fix is easy so I will prepare one and open an pull request...

@aryoda
Copy link
Contributor

aryoda commented Sep 8, 2022

Note: The unit test also fails if the crontab contains only empty lines (one or more) since this is also stripped and split into the erroneous [''] (list of length 1 instead 0)

@emtiu emtiu closed this as completed in e8b02bd Sep 8, 2022
emtiu added a commit that referenced this issue Sep 8, 2022
Closes #1181: test_readWriteCrontab fails when crontab is empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants