Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kattis-command
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Henke
kattis-command
Commits
be5d940a
Commit
be5d940a
authored
Mar 5, 2018
by
Henke
Browse files
Options
Downloads
Patches
Plain Diff
Finish implementation for
#3
parent
d5ae80c1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
kattcmd/core.py
+7
-2
7 additions, 2 deletions
kattcmd/core.py
test/test_core.py
+40
-2
40 additions, 2 deletions
test/test_core.py
with
47 additions
and
4 deletions
kattcmd/core.py
+
7
−
2
View file @
be5d940a
import
ast
import
os
import
os
import
configparser
import
configparser
...
@@ -26,7 +27,7 @@ def TouchStructure():
...
@@ -26,7 +27,7 @@ def TouchStructure():
}
}
with
open
(
kattcmd_file
,
'
w
'
)
as
configfile
:
with
open
(
kattcmd_file
,
'
w
'
)
as
configfile
:
config
file
.
write
(
config
)
config
.
write
(
config
file
)
return
True
return
True
return
False
return
False
...
@@ -42,7 +43,11 @@ def _ListExternals():
...
@@ -42,7 +43,11 @@ def _ListExternals():
config_path
=
os
.
path
.
expanduser
(
'
~/.kattcmd
'
)
config_path
=
os
.
path
.
expanduser
(
'
~/.kattcmd
'
)
config
=
configparser
.
ConfigParser
()
config
=
configparser
.
ConfigParser
()
config
.
read
(
config_path
)
config
.
read
(
config_path
)
return
config
[
'
options
'
][
'
plugins
'
]
# See https://stackoverflow.com/questions/1894269/convert-string-representation-of-list-to-list-in-python
# for why we use ast.literal_eval here
L
=
ast
.
literal_eval
(
config
[
'
options
'
][
'
plugins
'
])
return
[
x
.
strip
()
for
x
in
L
if
x
.
strip
()]
def
ListPlugins
():
def
ListPlugins
():
...
...
This diff is collapsed.
Click to expand it.
test/test_core.py
+
40
−
2
View file @
be5d940a
import
os
import
os
import
tempfile
import
configparser
from
kattcmd
import
core
from
kattcmd
import
core
def
test_one_plus_one
():
def
with_custom_home
(
f
):
assert
1
+
1
==
2
'''
Descriptor for tests that should run in their own isolated environment.
'''
def
inner
(
*
args
,
**
kwargs
):
with
tempfile
.
TemporaryDirectory
()
as
tempdirname
:
os
.
environ
[
'
HOME
'
]
=
tempdirname
f
(
*
args
,
**
kwargs
)
return
inner
@with_custom_home
def
test_creates_kattcmd_options
():
assert
core
.
TouchStructure
()
kattcmd_path
=
os
.
path
.
expanduser
(
'
~/.kattcmd
'
)
assert
os
.
path
.
isfile
(
kattcmd_path
)
config
=
configparser
.
ConfigParser
()
config
.
read
(
kattcmd_path
)
assert
'
options
'
in
config
assert
'
kattisrc
'
in
config
[
'
options
'
]
assert
'
plugins
'
in
config
[
'
options
'
]
@with_custom_home
def
test_touch_twice
():
assert
core
.
TouchStructure
()
assert
not
core
.
TouchStructure
()
@with_custom_home
def
test_lists_plugins
():
assert
core
.
TouchStructure
()
plugins
=
core
.
ListPlugins
()
assert
isinstance
(
plugins
,
list
)
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