Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
catalog
Tools
Commits
ba835122
Commit
ba835122
authored
1 year ago
by
Florian Ziemen
Browse files
Options
Downloads
Patches
Plain Diff
basic dataset class
parent
eded79cb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dataset.py
+37
-0
37 additions, 0 deletions
dataset.py
test_dataset.py
+47
-0
47 additions, 0 deletions
test_dataset.py
utils.py
+9
-0
9 additions, 0 deletions
utils.py
with
93 additions
and
0 deletions
dataset.py
0 → 100644
+
37
−
0
View file @
ba835122
import
utils
import
logging
from
collections.abc
import
Sequence
class
dataset_location
:
def
__init__
(
self
,
method
:
str
,
host
:
str
,
path
:
str
,
):
self
.
method
=
method
self
.
host
=
host
self
.
path
=
path
def
is_valid
(
self
)
->
bool
:
return
all
(
x
is
not
None
for
x
in
vars
(
self
).
values
())
class
dataset
:
def
__init__
(
self
,
name
:
str
,
serve
:
bool
,
locations
:
Sequence
[
dataset_location
],
**
kwargs
):
self
.
name
=
name
self
.
serve
=
serve
self
.
locations
=
set
(
locations
)
for
k
,
v
in
kwargs
.
items
():
setattr
(
self
,
k
,
v
)
def
is_valid
(
self
)
->
bool
:
return
(
all
(
x
is
not
None
for
x
in
vars
(
self
).
values
())
and
type
(
self
.
serve
)
is
bool
and
all
(
type
(
x
)
is
dataset_location
for
x
in
self
.
locations
)
and
all
(
x
.
is_valid
()
for
x
in
self
.
locations
)
)
This diff is collapsed.
Click to expand it.
test_dataset.py
0 → 100644
+
47
−
0
View file @
ba835122
import
dataset
import
unittest
class
test_dataset
(
unittest
.
TestCase
):
def
test_dataset
(
self
):
dsl1
=
dataset
.
dataset_location
(
method
=
"
direct
"
,
host
=
"
local
"
,
path
=
"
/scratch/
"
)
ds
=
dataset
.
dataset
(
name
=
"
test_ds
"
,
serve
=
True
,
locations
=
(
dsl1
,))
self
.
assertTrue
(
ds
.
is_valid
())
dsl2
=
dataset
.
dataset_location
(
method
=
"
direct
"
,
host
=
"
local
"
,
path
=
"
/work/
"
)
ds
=
dataset
.
dataset
(
name
=
"
test_ds
"
,
serve
=
True
,
locations
=
(
dsl1
,
dsl2
))
self
.
assertTrue
(
ds
.
is_valid
())
def
test_bad_dataset_location
(
self
):
badhost
=
dataset
.
dataset_location
(
method
=
"
direct
"
,
host
=
None
,
path
=
"
/scratch/
"
)
self
.
assertFalse
(
badhost
.
is_valid
())
badpath
=
dataset
.
dataset_location
(
method
=
"
direct
"
,
host
=
"
local
"
,
path
=
None
)
self
.
assertFalse
(
badpath
.
is_valid
())
badmethod
=
dataset
.
dataset_location
(
method
=
None
,
host
=
"
local
"
,
path
=
"
/scratch
"
)
self
.
assertFalse
(
badmethod
.
is_valid
())
def
test_bad_dataset
(
self
):
dsl1
=
dataset
.
dataset_location
(
method
=
"
direct
"
,
host
=
"
local
"
,
path
=
"
/scratch/
"
)
bad_name
=
dataset
.
dataset
(
name
=
None
,
serve
=
True
,
locations
=
(
dsl1
,))
self
.
assertFalse
(
bad_name
.
is_valid
())
bad_serve
=
dataset
.
dataset
(
name
=
"
test
"
,
serve
=
7
,
locations
=
(
dsl1
,))
self
.
assertFalse
(
bad_serve
.
is_valid
())
with
self
.
assertRaises
(
TypeError
):
bad_location
=
dataset
.
dataset
(
name
=
None
,
serve
=
True
,
locations
=
dsl1
)
badpath
=
dataset
.
dataset_location
(
method
=
"
direct
"
,
host
=
"
local
"
,
path
=
None
)
bad_location
=
dataset
.
dataset
(
name
=
None
,
serve
=
True
,
locations
=
(
badpath
,))
self
.
assertFalse
(
bad_location
.
is_valid
())
bad_location
=
dataset
.
dataset
(
name
=
None
,
serve
=
True
,
locations
=
(
None
,))
self
.
assertFalse
(
bad_location
.
is_valid
())
if
__name__
==
"
__main__
"
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
utils.py
0 → 100644
+
9
−
0
View file @
ba835122
from
urllib.parse
import
urlparse
def
check_url
(
url
):
result
=
urlparse
(
url
)
if
result
.
scheme
and
result
.
netloc
:
return
True
else
:
return
False
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