file() is not present in Python 3.
Details
Details
- Reviewers
durin42 - Group Reviewers
hg-reviewers - Commits
- rHG1dbd8a62b581: py3: use open() instead of file()
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| durin42 |
| hg-reviewers |
file() is not present in Python 3.
| Lint Skipped |
| Unit Tests Skipped |
| Test interactions between mq and patch.eol | Test interactions between mq and patch.eol | ||||
| $ cat <<EOF >> $HGRCPATH | $ cat <<EOF >> $HGRCPATH | ||||
| > [extensions] | > [extensions] | ||||
| > mq = | > mq = | ||||
| > [diff] | > [diff] | ||||
| > nodates = 1 | > nodates = 1 | ||||
| > EOF | > EOF | ||||
| $ cat > makepatch.py <<EOF | $ cat > makepatch.py <<EOF | ||||
| > f = file('eol.diff', 'wb') | > f = open('eol.diff', 'wb') | ||||
| > w = f.write | > w = f.write | ||||
| > w('test message\n') | > w('test message\n') | ||||
| > w('diff --git a/a b/a\n') | > w('diff --git a/a b/a\n') | ||||
| > w('--- a/a\n') | > w('--- a/a\n') | ||||
| > w('+++ b/a\n') | > w('+++ b/a\n') | ||||
| > w('@@ -1,5 +1,5 @@\n') | > w('@@ -1,5 +1,5 @@\n') | ||||
| > w(' a\n') | > w(' a\n') | ||||
| > w('-b\r\n') | > w('-b\r\n') | ||||
| > w('+y\r\n') | > w('+y\r\n') | ||||
| > w(' c\r\n') | > w(' c\r\n') | ||||
| > w(' d\n') | > w(' d\n') | ||||
| > w('-e\n') | > w('-e\n') | ||||
| > w('\ No newline at end of file\n') | > w('\ No newline at end of file\n') | ||||
| > w('+z\r\n') | > w('+z\r\n') | ||||
| > w('\ No newline at end of file\r\n') | > w('\ No newline at end of file\r\n') | ||||
| > EOF | > EOF | ||||
| $ cat > cateol.py <<EOF | $ cat > cateol.py <<EOF | ||||
| > import sys | > import sys | ||||
| > for line in file(sys.argv[1], 'rb'): | > for line in open(sys.argv[1], 'rb'): | ||||
| > line = line.replace('\r', '<CR>') | > line = line.replace('\r', '<CR>') | ||||
| > line = line.replace('\n', '<LF>') | > line = line.replace('\n', '<LF>') | ||||
| > print(line) | > print(line) | ||||
| > EOF | > EOF | ||||
| $ hg init repo | $ hg init repo | ||||
| $ cd repo | $ cd repo | ||||
| $ echo '\.diff' > .hgignore | $ echo '\.diff' > .hgignore | ||||
| $ echo '\.rej' >> .hgignore | $ echo '\.rej' >> .hgignore | ||||
| Test different --eol values | Test different --eol values | ||||
| $ $PYTHON -c 'file("a", "wb").write("a\nb\nc\nd\ne")' | $ $PYTHON -c 'open("a", "wb").write("a\nb\nc\nd\ne")' | ||||
| $ hg ci -Am adda | $ hg ci -Am adda | ||||
| adding .hgignore | adding .hgignore | ||||
| adding a | adding a | ||||
| $ $PYTHON ../makepatch.py | $ $PYTHON ../makepatch.py | ||||
| $ hg qimport eol.diff | $ hg qimport eol.diff | ||||
| adding eol.diff to series file | adding eol.diff to series file | ||||
| should fail in strict mode | should fail in strict mode | ||||
| patch queue now empty | patch queue now empty | ||||
| $ cd .. | $ cd .. | ||||
| Test .rej file EOL are left unchanged | Test .rej file EOL are left unchanged | ||||
| $ hg init testeol | $ hg init testeol | ||||
| $ cd testeol | $ cd testeol | ||||
| $ $PYTHON -c "file('a', 'wb').write('1\r\n2\r\n3\r\n4')" | $ $PYTHON -c "open('a', 'wb').write('1\r\n2\r\n3\r\n4')" | ||||
| $ hg ci -Am adda | $ hg ci -Am adda | ||||
| adding a | adding a | ||||
| $ $PYTHON -c "file('a', 'wb').write('1\r\n2\r\n33\r\n4')" | $ $PYTHON -c "open('a', 'wb').write('1\r\n2\r\n33\r\n4')" | ||||
| $ hg qnew patch1 | $ hg qnew patch1 | ||||
| $ hg qpop | $ hg qpop | ||||
| popping patch1 | popping patch1 | ||||
| patch queue now empty | patch queue now empty | ||||
| $ $PYTHON -c "file('a', 'wb').write('1\r\n22\r\n33\r\n4')" | $ $PYTHON -c "open('a', 'wb').write('1\r\n22\r\n33\r\n4')" | ||||
| $ hg ci -m changea | $ hg ci -m changea | ||||
| $ hg --config 'patch.eol=LF' qpush | $ hg --config 'patch.eol=LF' qpush | ||||
| applying patch1 | applying patch1 | ||||
| patching file a | patching file a | ||||
| Hunk #1 FAILED at 0 | Hunk #1 FAILED at 0 | ||||
| 1 out of 1 hunks FAILED -- saving rejects to file a.rej | 1 out of 1 hunks FAILED -- saving rejects to file a.rej | ||||
| patch failed, unable to continue (try -v) | patch failed, unable to continue (try -v) | ||||