Mercurial > python-hglib
annotate tests/test-import.py @ 146:8d7bf729a4db
hglib: use io.BytesIO when available (issue4520)
Since cStringIO.StringIO is not available in Python 3, try to use
io.BytesIO when available.
author | Brett Cannon <brett@python.org> |
---|---|
date | Fri, 13 Mar 2015 11:34:52 -0400 |
parents | f3c430afa598 |
children | 98829bf71f10 |
rev | line source |
---|---|
145
f3c430afa598
hglib: abstract out use of cStringIO.StringIO (issue4520)
Brett Cannon <brett@python.org>
parents:
143
diff
changeset
|
1 import common, os |
146
8d7bf729a4db
hglib: use io.BytesIO when available (issue4520)
Brett Cannon <brett@python.org>
parents:
145
diff
changeset
|
2 try: |
8d7bf729a4db
hglib: use io.BytesIO when available (issue4520)
Brett Cannon <brett@python.org>
parents:
145
diff
changeset
|
3 from io import BytesIO |
8d7bf729a4db
hglib: use io.BytesIO when available (issue4520)
Brett Cannon <brett@python.org>
parents:
145
diff
changeset
|
4 except ImportError: |
8d7bf729a4db
hglib: use io.BytesIO when available (issue4520)
Brett Cannon <brett@python.org>
parents:
145
diff
changeset
|
5 from cStringIO import StringIO as BytesIO |
7
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 import hglib |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
118
diff
changeset
|
7 from hglib.util import b |
7
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
118
diff
changeset
|
9 patch = b(""" |
7
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 # HG changeset patch |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 # User test |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 # Date 0 0 |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 # Node ID c103a3dec114d882c98382d684d8af798d09d857 |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 # Parent 0000000000000000000000000000000000000000 |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
15 1 |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 diff -r 000000000000 -r c103a3dec114 a |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 +++ b/a Thu Jan 01 00:00:00 1970 +0000 |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 @@ -0,0 +1,1 @@ |
eac8be119d81
tests: rearrange tests and use nosetests
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 +1 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
118
diff
changeset
|
22 """) |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
7
diff
changeset
|
23 |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
7
diff
changeset
|
24 class test_import(common.basetest): |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
7
diff
changeset
|
25 def test_basic_cstringio(self): |
145
f3c430afa598
hglib: abstract out use of cStringIO.StringIO (issue4520)
Brett Cannon <brett@python.org>
parents:
143
diff
changeset
|
26 self.client.import_(BytesIO(patch)) |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
118
diff
changeset
|
27 self.assertEquals(self.client.cat([b('a')]), b('1\n')) |
13
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
7
diff
changeset
|
28 |
400cb1520834
client: add missing options to import_()
Idan Kamara <idankk86@gmail.com>
parents:
7
diff
changeset
|
29 def test_basic_file(self): |
118
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
96
diff
changeset
|
30 f = open('patch', 'wb') |
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
96
diff
changeset
|
31 f.write(patch) |
e738d6fe5f3f
tests: make the tests work under Pypy (issue3965)
Matt Mackall <mpm@selenic.com>
parents:
96
diff
changeset
|
32 f.close() |
96
9746227239e0
client: fix import --no-commit flag (issue3206)
Idan Kamara <idankk86@gmail.com>
parents:
68
diff
changeset
|
33 |
9746227239e0
client: fix import --no-commit flag (issue3206)
Idan Kamara <idankk86@gmail.com>
parents:
68
diff
changeset
|
34 # --no-commit |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
118
diff
changeset
|
35 self.client.import_([b('patch')], nocommit=True) |
96
9746227239e0
client: fix import --no-commit flag (issue3206)
Idan Kamara <idankk86@gmail.com>
parents:
68
diff
changeset
|
36 self.assertEquals(open('a').read(), '1\n') |
9746227239e0
client: fix import --no-commit flag (issue3206)
Idan Kamara <idankk86@gmail.com>
parents:
68
diff
changeset
|
37 |
9746227239e0
client: fix import --no-commit flag (issue3206)
Idan Kamara <idankk86@gmail.com>
parents:
68
diff
changeset
|
38 self.client.update(clean=True) |
9746227239e0
client: fix import --no-commit flag (issue3206)
Idan Kamara <idankk86@gmail.com>
parents:
68
diff
changeset
|
39 os.remove('a') |
9746227239e0
client: fix import --no-commit flag (issue3206)
Idan Kamara <idankk86@gmail.com>
parents:
68
diff
changeset
|
40 |
143
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
118
diff
changeset
|
41 self.client.import_([b('patch')]) |
4359cabcb0cc
hglib: move string literals in the test code to util.b() (issue4520)
Brett Cannon <brett@python.org>
parents:
118
diff
changeset
|
42 self.assertEquals(self.client.cat([b('a')]), b('1\n')) |