Skip to content

Commit 608f8a6

Browse files
committed
version for issue with setup resource imports
1 parent f75a8e4 commit 608f8a6

File tree

5 files changed

+167
-127
lines changed

5 files changed

+167
-127
lines changed

dist/moon-1.1.7.tar.gz

409 KB
Binary file not shown.

moon/dialamoon.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
resource_path = '/'.join(('res', 'constants.json'))
1818
constants_string = pkg_resources.resource_string(resource_package, resource_path)
1919
CONSTANTS_JSON_DICT = json.loads(constants_string)
20+
else:
21+
# todo this is a workaround when troubleshooting importing resources with package_data
22+
CONSTANTS_JSON_DICT = {}
2023

2124
class Moon(CustomImage):
2225
def __init__(self, size=(1000,1000)):
@@ -81,6 +84,10 @@ def make_datetime(self, date, hour):
8184
def make_nasa_frame_id(self):
8285
#code logic courtesy of Ernie Wright
8386
year = self.datetime.year
87+
print("in make_nasa_frame_id:")
88+
print(self.datetime.year)
89+
print(self.svs_id)
90+
print()
8491

8592
#todo - check why we were checking that the year isn't 2019
8693
# if (year != 2019):
@@ -96,6 +103,10 @@ def make_nasa_frame_id(self):
96103
def make_moon_image_url(self):
97104
try:
98105
self.svs_id = self.SVS_ID_DICT[str(self.datetime.year)]
106+
print("in make_moon_image_url:")
107+
print("self.datetime.year is ", self.datetime.year)
108+
print("self.svs_id is ", self.svs_id)
109+
print()
99110
except KeyError as e:
100111
years_available = sorted(self.SVS_ID_DICT.keys())
101112
requested_year = self.datetime.year
@@ -122,7 +133,9 @@ def make_moon_image_url(self):
122133
else:
123134
raise e
124135

136+
125137
self.frame_id = self.make_nasa_frame_id()
138+
print("setting frame id: ", self.frame_id)
126139
return self.SVS_URL_BASE.format(
127140
year_id_modulo = str(self.svs_id - self.svs_id % 100),
128141
year_id = str(self.svs_id),
@@ -146,10 +159,28 @@ def make_json_year_mooninfo_url(self):
146159

147160
@lru_cache()
148161
def set_mooninfo_requested_year(self):
162+
149163
response = urllib.request.urlopen(self.json_url)
150164
self.moon_year_info = json.loads(response.read())
151165
return self.moon_year_info
152166

153167
def set_mooninfo_requested_date(self):
168+
try:
169+
print("going to try to update the moon_datetime_info: ")
170+
print(self.moon_datetime_info['time'])
171+
print(self.svs_id)
172+
print(self.get_moon_phase_date())
173+
print()
174+
except:
175+
print("no info yet")
176+
154177
self.moon_datetime_info = self.moon_year_info[int(self.frame_id) - 1]
178+
print("just tried to update moon_datetime_info:")
179+
print(self.moon_datetime_info['time'])
180+
print(self.svs_id)
181+
print(self.get_moon_phase_date())
182+
print()
183+
184+
185+
155186

moon/tests/cache.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
import unittest
2-
from ..dialamoon import Moon
3-
from ..terminal_ui import TerminalUi
4-
from datetime import datetime
5-
from time import sleep
6-
import numpy
7-
import copy
1+
# import unittest
2+
# from ..dialamoon import Moon
3+
# from ..terminal_ui import TerminalUi
4+
# from datetime import datetime
5+
# from time import sleep
6+
# import numpy
7+
# import copy
88

9-
class TestMoonCache(unittest.TestCase):
10-
def test_caches_json_year_data(self):
11-
m = Moon()
12-
m.set_moon_datetime(date="2019-01-01")
13-
m.make_json_year_mooninfo_url()
14-
time1 = datetime.now()
15-
m.set_mooninfo_requested_year()
16-
time2 = datetime.now()
17-
sleep(5)
18-
time3 = datetime.now()
19-
m.set_mooninfo_requested_year()
20-
time4 = datetime.now()
21-
assert (time4 - time3).seconds == 0
9+
# class TestMoonCache(unittest.TestCase):
10+
# def test_caches_json_year_data(self):
11+
# m = Moon()
12+
# m.set_moon_datetime(date="2019-01-01")
13+
# m.make_json_year_mooninfo_url()
14+
# time1 = datetime.now()
15+
# m.set_mooninfo_requested_year()
16+
# time2 = datetime.now()
17+
# sleep(5)
18+
# time3 = datetime.now()
19+
# m.set_mooninfo_requested_year()
20+
# time4 = datetime.now()
21+
# assert (time4 - time3).seconds == 0
2222

2323

24-
def test_changes_moon_image_on_second_request(self):
25-
m = Moon()
26-
m.set_moon_datetime("2019-01-01")
27-
m.request_moon_image()
28-
url1 = m.url
29-
im1 = copy.deepcopy(m.image)
30-
m.set_moon_datetime("2020-01-01")
31-
url2 = m.url
32-
m.request_moon_image()
33-
im2 = m.image
34-
assert url1 != url2 and not numpy.array_equal(im1,im2)
24+
# def test_changes_moon_image_on_second_request(self):
25+
# m = Moon()
26+
# m.set_moon_datetime("2019-01-01")
27+
# m.request_moon_image()
28+
# url1 = m.url
29+
# im1 = copy.deepcopy(m.image)
30+
# m.set_moon_datetime("2020-01-01")
31+
# url2 = m.url
32+
# m.request_moon_image()
33+
# im2 = m.image
34+
# assert url1 != url2 and not numpy.array_equal(im1,im2)
3535

36-
def test_caches_moon_image_from_first_request(self):
37-
m = TerminalUi()
38-
m.set_moon_datetime("2020-01-06")
39-
m.request_moon_image()
40-
url1 = m.url
41-
im1 = copy.deepcopy(m.image)
42-
m.set_moon_datetime("2020-01-01")
43-
url2 = m.url
44-
m.request_moon_image()
45-
im2 = copy.deepcopy( m.image)
46-
m.set_moon_datetime("2020-01-06")
47-
url3 = m.url
48-
time2 = datetime.now()
49-
m.request_moon_image()
50-
time3 = datetime.now()
51-
im3 = copy.deepcopy(m.image)
52-
assert url1 == url3 and numpy.array_equal(im1,im3) and (time3 - time2).seconds == 0
53-
assert numpy.array_equal(im1,im3)
36+
# def test_caches_moon_image_from_first_request(self):
37+
# m = TerminalUi()
38+
# m.set_moon_datetime("2020-01-06")
39+
# m.request_moon_image()
40+
# url1 = m.url
41+
# im1 = copy.deepcopy(m.image)
42+
# m.set_moon_datetime("2020-01-01")
43+
# url2 = m.url
44+
# m.request_moon_image()
45+
# im2 = copy.deepcopy( m.image)
46+
# m.set_moon_datetime("2020-01-06")
47+
# url3 = m.url
48+
# time2 = datetime.now()
49+
# m.request_moon_image()
50+
# time3 = datetime.now()
51+
# im3 = copy.deepcopy(m.image)
52+
# assert url1 == url3 and numpy.array_equal(im1,im3) and (time3 - time2).seconds == 0
53+
# assert numpy.array_equal(im1,im3)
5454

55-
def test_gets_json_year_data(self):
56-
m = Moon()
57-
m.set_moon_datetime("2019-01-01")
58-
m.make_json_year_mooninfo_url()
59-
m.set_mooninfo_requested_year()
60-
assert m.moon_year_info[0]["time"] == '01 Jan 2019 00:00 UT'
55+
# def test_gets_json_year_data(self):
56+
# m = Moon()
57+
# m.set_moon_datetime("2019-01-01")
58+
# m.make_json_year_mooninfo_url()
59+
# m.set_mooninfo_requested_year()
60+
# assert m.moon_year_info[0]["time"] == '01 Jan 2019 00:00 UT'
6161

6262

63-
def test_saves_time_getting_same_moon_image(self):
64-
m = Moon()
65-
m.set_moon_datetime("2019-01-01")
66-
m.request_moon_image()
67-
m.set_moon_datetime("2019-01-02")
68-
m.request_moon_image()
69-
time1 = datetime.now()
70-
m.request_moon_image()
71-
time2 = datetime.now()
72-
assert (time2 - time1).seconds == 0
63+
# def test_saves_time_getting_same_moon_image(self):
64+
# m = Moon()
65+
# m.set_moon_datetime("2019-01-01")
66+
# m.request_moon_image()
67+
# m.set_moon_datetime("2019-01-02")
68+
# m.request_moon_image()
69+
# time1 = datetime.now()
70+
# m.request_moon_image()
71+
# time2 = datetime.now()
72+
# assert (time2 - time1).seconds == 0
7373

74-
if __name__ == '__main__':
75-
unittest.main()
74+
# if __name__ == '__main__':
75+
# unittest.main()

moon/tests/general.py

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,83 @@ def __init__(self, *args, **kwargs):
1010
super(TestMoon, self).__init__(*args, **kwargs)
1111
self.sm = Moon()
1212

13-
def test_returns_error_for_datetime_format_issue(self):
14-
m = Moon()
15-
self.assertRaises(ValueError, m.set_moon_datetime, "190-01-01")
13+
# def test_returns_error_for_datetime_format_issue(self):
14+
# m = Moon()
15+
# self.assertRaises(ValueError, m.set_moon_datetime, "190-01-01")
1616

17-
def test_returns_helpful_error_for_datetime_range_issue(self):
18-
m = Moon()
19-
self.assertRaisesRegex(KeyError, r"Cannot find year .* in this version "\
20-
"of the package. This package can get moons for years .* -"\
21-
" .*. Please try a different year or check for an update "\
22-
"for this package.",
23-
m.set_moon_datetime, "1900-01-01")
17+
# def test_returns_helpful_error_for_datetime_range_issue(self):
18+
# m = Moon()
19+
# self.assertRaisesRegex(KeyError, r"Cannot find year .* in this version "\
20+
# "of the package. This package can get moons for years .* -"\
21+
# " .*. Please try a different year or check for an update "\
22+
# "for this package.",
23+
# m.set_moon_datetime, "1900-01-01")
2424

25-
def test_makes_a_moon_image_url(self):
26-
m = Moon()
27-
m.set_moon_datetime(date="2019-01-01", hour=0)
28-
assert m.url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/"\
29-
"a004442/frames/730x730_1x1_30p/moon.0001.jpg"
25+
# def test_makes_a_moon_image_url(self):
26+
# m = Moon()
27+
# m.set_moon_datetime(date="2019-01-01", hour=0)
28+
# assert m.url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/"\
29+
# "a004442/frames/730x730_1x1_30p/moon.0001.jpg"
3030

31-
def test_makes_a_json_data_url(self):
32-
m = Moon()
33-
m.set_moon_datetime("2019-01-01")
34-
m.make_json_year_mooninfo_url()
35-
assert m.json_url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/mooninfo_2019.json"
31+
# def test_makes_a_json_data_url(self):
32+
# m = Moon()
33+
# m.set_moon_datetime("2019-01-01")
34+
# m.make_json_year_mooninfo_url()
35+
# assert m.json_url == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/mooninfo_2019.json"
3636

37-
def test_gets_json_for_requested_datetime(self):
38-
m = Moon()
39-
m.set_moon_datetime(date="2019-01-01", hour=1)
40-
m.make_json_year_mooninfo_url()
41-
m.set_mooninfo_requested_year()
42-
m.set_mooninfo_requested_date()
43-
assert m.moon_datetime_info["time"] == '01 Jan 2019 01:00 UT'
37+
# def test_gets_json_for_requested_datetime(self):
38+
# m = Moon()
39+
# m.set_moon_datetime(date="2019-01-01", hour=1)
40+
# m.make_json_year_mooninfo_url()
41+
# m.set_mooninfo_requested_year()
42+
# m.set_mooninfo_requested_date()
43+
# assert m.moon_datetime_info["time"] == '01 Jan 2019 01:00 UT'
4444

45-
def test_gets_moon_image_as_numpy_array(self):
46-
m = Moon()
47-
m.set_moon_datetime("2019-01-01")
48-
m.request_moon_image()
49-
self.assertIs(type(m.image), numpy.ndarray)
45+
# def test_gets_moon_image_as_numpy_array(self):
46+
# m = Moon()
47+
# m.set_moon_datetime("2019-01-01")
48+
# m.request_moon_image()
49+
# self.assertIs(type(m.image), numpy.ndarray)
5050

51-
def test_takes_optional_hour_arg(self):
52-
m = Moon()
53-
m.set_moon_datetime(hour=1)
54-
assert m.datetime.hour == 1
51+
# def test_takes_optional_hour_arg(self):
52+
# m = Moon()
53+
# m.set_moon_datetime(hour=1)
54+
# assert m.datetime.hour == 1
5555

56-
def test_can_get_last_hour_of_nonleap_year(self):
57-
m = Moon()
58-
m.set_moon_datetime(date="2019-12-31", hour=23)
59-
m.request_moon_image()
60-
m.make_json_year_mooninfo_url()
61-
m.set_mooninfo_requested_year()
62-
m.set_mooninfo_requested_date()
56+
# def test_can_get_last_hour_of_nonleap_year(self):
57+
# m = Moon()
58+
# m.set_moon_datetime(date="2019-12-31", hour=23)
59+
# m.request_moon_image()
60+
# m.make_json_year_mooninfo_url()
61+
# m.set_mooninfo_requested_year()
62+
# m.set_mooninfo_requested_date()
6363

64-
assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/"\
65-
"frames/730x730_1x1_30p/moon.8760.jpg"
64+
# assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004400/a004442/"\
65+
# "frames/730x730_1x1_30p/moon.8760.jpg"
6666

67-
def test_can_get_last_hour_of_year(self):
68-
m = Moon()
69-
m.set_moon_datetime(date="2020-12-31", hour=23)
70-
m.request_moon_image()
71-
assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004700/a004768/"\
72-
"frames/730x730_1x1_30p/moon.8784.jpg"
67+
# def test_can_get_last_hour_of_year(self):
68+
# m = Moon()
69+
# m.set_moon_datetime(date="2020-12-31", hour=23)
70+
# m.request_moon_image()
71+
# assert m.image_src == "https://svs.gsfc.nasa.gov/vis/a000000/a004700/a004768/"\
72+
# "frames/730x730_1x1_30p/moon.8784.jpg"
73+
74+
# def test_can_get_moon_for_2022(self):
75+
# # note: this is just helpful for testing a version of `moon` where
76+
# # the SVS_ID has been added to the github repo but the user
77+
# # hasn't updated the package to include the new SVS_ID
78+
# m = Moon()
79+
# m.set_moon_datetime(date="2022-01-15")
80+
# m.request_moon_image()
81+
# assert m.SVS_ID_DICT["2022"] == 4955
7382

74-
def test_can_get_moon_for_2022(self):
75-
# note: this is just helpful for testing a version of `moon` where
76-
# the SVS_ID has been added to the github repo but the user
77-
# hasn't updated the package to include the new SVS_ID
83+
def test_gets_new_moon_info_if_another_year_requested(self):
7884
m = Moon()
79-
m.set_moon_datetime(date="2022-01-15")
80-
m.request_moon_image()
81-
assert m.SVS_ID_DICT["2022"] == 4955
85+
m.set_moon_phase("2019-01-15")
86+
# print(m.moon_datetime_info['time'])
87+
m.set_moon_phase("2020-01-16")
88+
# print(m.moon_datetime_info['time'])
89+
assert m.moon_datetime_info['time'] == '15 Jan 2020 09:00 UT'
8290

8391

8492
if __name__ == '__main__':

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
setup(
99
name = 'moon',
1010
packages = find_packages(),
11-
version = '1.1.5',
11+
version = '1.1.7',
1212
license='MIT',
1313
description = 'Gets moon visualizations courtesy of SVS, NASA, Ernie Wright',
1414
long_description_content_type="text/markdown",
1515
long_description = long_description,
1616
author = 'Sadie Parker',
1717
author_email = 'sadiemparker@gmail.com',
1818
url = 'https://github.com/spacerest/moon',
19-
download_url = 'https://github.com/spacerest/moon/archive/v_1_1_5.tar.gz',
19+
download_url = 'https://github.com/spacerest/moon/archive/v_1_1_7.tar.gz',
2020
keywords = ['MOON', 'ART'],
2121
install_requires=[
2222
'numpy~=1.16',
@@ -34,5 +34,6 @@
3434
'Programming Language :: Python :: 3.6',
3535
],
3636
package_data={'constants': ['res/constants.json']},
37+
include_package_data=True
3738

3839
)

0 commit comments

Comments
 (0)