Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mercurial
mercurial-devel
Commits
fb9d1c2805ff
Commit
fb9d1c2805ff
authored
12 years ago
by
Idan Kamara
Browse files
Options
Downloads
Patches
Plain Diff
test-atomictempfile: convert to unit test
parent
2cbfb8c497ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test-atomictempfile.py
+31
-37
31 additions, 37 deletions
tests/test-atomictempfile.py
tests/test-atomictempfile.py.out
+0
-3
0 additions, 3 deletions
tests/test-atomictempfile.py.out
with
31 additions
and
40 deletions
tests/test-atomictempfile.py
+
31
−
37
View file @
fb9d1c28
import
os
import
glob
import
unittest
import
silenttestrunner
from
mercurial.util
import
atomictempfile
...
...
@@ -3,11 +6,11 @@
from
mercurial.util
import
atomictempfile
# basic usage
def
test1_simple
():
if
os
.
path
.
exists
(
'
foo
'
):
os
.
remove
(
'
foo
'
)
file
=
atomictempfile
(
'
foo
'
)
(
dir
,
basename
)
=
os
.
path
.
split
(
file
.
_tempname
)
assert
not
os
.
path
.
isfile
(
'
foo
'
)
assert
basename
in
glob
.
glob
(
'
.foo-*
'
)
class
testatomictempfile
(
unittest
.
TestCase
):
def
test1_simple
(
self
):
if
os
.
path
.
exists
(
'
foo
'
):
os
.
remove
(
'
foo
'
)
file
=
atomictempfile
(
'
foo
'
)
(
dir
,
basename
)
=
os
.
path
.
split
(
file
.
_tempname
)
self
.
assertFalse
(
os
.
path
.
isfile
(
'
foo
'
)
)
self
.
assert
True
(
basename
in
glob
.
glob
(
'
.foo-*
'
)
)
...
...
@@ -13,4 +16,4 @@
file
.
write
(
'
argh
\n
'
)
file
.
close
()
file
.
write
(
'
argh
\n
'
)
file
.
close
()
...
...
@@ -16,5 +19,4 @@
assert
os
.
path
.
isfile
(
'
foo
'
)
assert
basename
not
in
glob
.
glob
(
'
.foo-*
'
)
print
'
OK
'
self
.
assertTrue
(
os
.
path
.
isfile
(
'
foo
'
))
self
.
assertTrue
(
basename
not
in
glob
.
glob
(
'
.foo-*
'
))
...
...
@@ -20,11 +22,8 @@
# discard() removes the temp file without making the write permanent
def
test2_discard
():
if
os
.
path
.
exists
(
'
foo
'
):
os
.
remove
(
'
foo
'
)
file
=
atomictempfile
(
'
foo
'
)
(
dir
,
basename
)
=
os
.
path
.
split
(
file
.
_tempname
)
file
.
write
(
'
yo
\n
'
)
file
.
discard
()
# discard() removes the temp file without making the write permanent
def
test2_discard
(
self
):
if
os
.
path
.
exists
(
'
foo
'
):
os
.
remove
(
'
foo
'
)
file
=
atomictempfile
(
'
foo
'
)
(
dir
,
basename
)
=
os
.
path
.
split
(
file
.
_tempname
)
...
...
@@ -30,5 +29,4 @@
assert
not
os
.
path
.
isfile
(
'
foo
'
)
assert
basename
not
in
os
.
listdir
(
'
.
'
)
print
'
OK
'
file
.
write
(
'
yo
\n
'
)
file
.
discard
()
...
...
@@ -34,12 +32,10 @@
# if a programmer screws up and passes bad args to atomictempfile, they
# get a plain ordinary TypeError, not infinite recursion
def
test3_oops
():
try
:
file
=
atomictempfile
()
except
TypeError
:
print
"
OK
"
else
:
print
"
expected TypeError
"
self
.
assertFalse
(
os
.
path
.
isfile
(
'
foo
'
))
self
.
assertTrue
(
basename
not
in
os
.
listdir
(
'
.
'
))
# if a programmer screws up and passes bad args to atomictempfile, they
# get a plain ordinary TypeError, not infinite recursion
def
test3_oops
(
self
):
self
.
assertRaises
(
TypeError
,
atomictempfile
)
if
__name__
==
'
__main__
'
:
...
...
@@ -44,5 +40,3 @@
if
__name__
==
'
__main__
'
:
test1_simple
()
test2_discard
()
test3_oops
()
silenttestrunner
.
main
(
__name__
)
This diff is collapsed.
Click to expand it.
tests/test-atomictempfile.py.out
deleted
100644 → 0
+
0
−
3
View file @
2cbfb8c4
OK
OK
OK
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment