Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
julday
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Software Public
PASSOFT
julday
Commits
2f8bdbab
Commit
2f8bdbab
authored
4 years ago
by
Maeva Pourpoint
Browse files
Options
Downloads
Patches
Plain Diff
A few more unit tests
parent
08ea7a3a
No related branches found
Branches containing commit
No related tags found
2 merge requests
!2
Update conda recipe to build python and platform independent package
,
!1
Update code to run under Python3 + Conda packaging
Pipeline
#751
passed with stages
in 1 minute and 6 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
julday/julday.py
+4
-9
4 additions, 9 deletions
julday/julday.py
tests/test_julday.py
+24
-12
24 additions, 12 deletions
tests/test_julday.py
with
28 additions
and
21 deletions
julday/julday.py
+
4
−
9
View file @
2f8bdbab
...
...
@@ -21,9 +21,7 @@ import datetime
def
usage
():
"""
Prints the usage.
"""
"""
Prints the usage.
"""
print
(
'
Usage : {} mm dd [year]
'
.
format
(
sys
.
argv
[
0
]))
...
...
@@ -44,7 +42,7 @@ def cal_to_jul(argv):
calendar_date
=
datetime
.
datetime
.
today
().
strftime
(
"
%m %d %Y
"
)
if
is_date_valid
(
calendar_date
):
print
(
'
\n
Calendar Date
'
+
calendar_date
)
print
(
'
\n
Calendar Date
{}
'
.
format
(
calendar_date
)
)
# Parse string to a datetime object.
d
=
datetime
.
datetime
.
strptime
(
calendar_date
,
"
%m %d %Y
"
)
# Format d to a julian date that can be printed.
...
...
@@ -60,9 +58,7 @@ def cal_to_jul(argv):
def
is_date_valid
(
calendar_date
):
"""
Check if the date of the year is valid.
"""
"""
Check if the date of the year is valid.
"""
try
:
# strptime will raise an error if day, month, or year is out of range
datetime
.
datetime
.
strptime
(
calendar_date
,
"
%m %d %Y
"
)
...
...
@@ -76,10 +72,9 @@ def main():
julday takes either no arguments, the month and day, or a month, day, and
year as arguments
"""
if
len
(
sys
.
argv
)
==
1
or
len
(
sys
.
argv
)
>
4
:
if
len
(
sys
.
argv
)
not
in
[
1
,
3
,
4
]
:
usage
()
sys
.
exit
(
1
)
cal_to_jul
(
sys
.
argv
[
1
:])
...
...
This diff is collapsed.
Click to expand it.
tests/test_julday.py
+
24
−
12
View file @
2f8bdbab
...
...
@@ -10,7 +10,8 @@ from unittest.mock import patch
from
julday.julday
import
is_date_valid
,
cal_to_jul
VALID_DATE
=
[
'
04
'
,
'
02
'
,
'
2020
'
]
UNVALID_DATE
=
[
'
13
'
,
'
02
'
,
'
2020
'
]
UNVALID_MONTH
=
[
'
13
'
,
'
02
'
,
'
2020
'
]
UNVALID_YEAR
=
[
'
04
'
,
'
02
'
,
'
-2050
'
]
class
TestJulday
(
unittest
.
TestCase
):
...
...
@@ -21,19 +22,30 @@ class TestJulday(unittest.TestCase):
calendar_date_valid
=
"
{} {} {}
"
.
format
(
VALID_DATE
[
0
],
VALID_DATE
[
1
],
VALID_DATE
[
2
])
calendar_date_unvalid
=
"
{} {} {}
"
.
format
(
UNVALID_DATE
[
0
],
UNVALID_DATE
[
1
],
UNVALID_DATE
[
2
])
calendar_date_unvalid_1
=
"
{} {} {}
"
.
format
(
UNVALID_MONTH
[
0
],
UNVALID_MONTH
[
1
],
UNVALID_MONTH
[
2
])
calendar_date_unvalid_2
=
"
{} {} {}
"
.
format
(
UNVALID_YEAR
[
0
],
UNVALID_YEAR
[
1
],
UNVALID_YEAR
[
2
])
self
.
assertTrue
(
is_date_valid
(
calendar_date_valid
),
'
{} is not a valid date
'
.
format
(
calendar_date_valid
))
self
.
assertFalse
(
is_date_valid
(
calendar_date_unvalid
),
'
{} is a valid date
'
.
format
(
calendar_date_unvalid
))
"
{} is not a valid date
"
.
format
(
calendar_date_valid
))
self
.
assertFalse
(
is_date_valid
(
calendar_date_unvalid_1
),
"
{} is a valid date
"
.
format
(
calendar_date_unvalid_1
))
self
.
assertFalse
(
is_date_valid
(
calendar_date_unvalid_2
),
"
{} is a valid date
"
.
format
(
calendar_date_unvalid_2
))
@patch
(
'
julday.julday.sys.exit
'
,
autospec
=
True
)
@patch
(
'
sys.stdout
'
,
new_callable
=
io
.
StringIO
)
def
test_cal_to_jul
(
self
,
mock_stdout
):
def
test_cal_to_jul
(
self
,
mock_stdout
,
mock_exit
):
"""
Test basic functionality of cal_to_jul function
"""
cal_to_jul
(
VALID_DATE
)
cal_to_jul
(
VALID_DATE
[
0
:
2
]
)
output
=
'
\n
Calendar Date 04 02 2020
\n
Julian Date 093 2020
\n\n
'
self
.
assertEqual
(
mock_stdout
.
getvalue
(),
output
,
'
Failed to properly convert date!
'
)
self
.
assertEqual
(
mock_stdout
.
getvalue
(),
output
,
"
Failed to properly convert date!
"
)
cal_to_jul
(
UNVALID_MONTH
)
self
.
assertTrue
(
mock_exit
.
called
,
"
sys.exit(1) never called -
"
"
cal_to_jul() not fully exercised!
"
)
cal_to_jul
(
UNVALID_YEAR
)
self
.
assertTrue
(
mock_exit
.
called
,
"
sys.exit(1) never called -
"
"
cal_to_jul() not fully exercised!
"
)
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