Corey Morris commited on
Commit
9adae3c
1 Parent(s): b58e1f0

Replicating 404 error with a test so I can troubleshoot

Browse files
details_data_processor.py CHANGED
@@ -48,7 +48,7 @@ class DetailsDataProcessor:
48
  # Format the timestamp as a string, suitable for use in a filename
49
  filename_timestamp = timestamp.strftime("%Y-%m-%dT%H-%M-%S")
50
 
51
- # Example usage in a filename
52
  save_file_path = save_file_path + filename_timestamp + ".json"
53
 
54
  print(save_file_path) # Output will be something like "results_2023-08-20T12-34-56.txt"
@@ -56,25 +56,30 @@ class DetailsDataProcessor:
56
  try:
57
  # Sending a GET request
58
  r = requests.get(url, allow_redirects=True)
59
- r.raise_for_status() # Raises an HTTPError if the HTTP request returned an unsuccessful status code
60
 
61
  # Writing the content to the specified file
62
  with open(save_file_path, 'wb') as file:
63
  file.write(r.content)
64
-
65
  print(f"Successfully downloaded file: {save_file_path}")
66
- except requests.ConnectionError:
67
  print(f"Failed to connect to the URL: {url}")
 
68
  except requests.HTTPError as e:
69
  print(f"HTTP error occurred: {e}")
70
- except FileNotFoundError:
 
71
  print(f"File not found at path: {save_file_path}")
 
72
  except Exception as e:
73
  print(f"An unexpected error occurred: {e}")
 
74
 
75
  return None
76
 
77
 
 
78
  @staticmethod
79
  def single_file_pipeline(url, filename):
80
  DetailsDataProcessor.download_file(url, filename)
 
48
  # Format the timestamp as a string, suitable for use in a filename
49
  filename_timestamp = timestamp.strftime("%Y-%m-%dT%H-%M-%S")
50
 
51
+ # Construct the full save file path
52
  save_file_path = save_file_path + filename_timestamp + ".json"
53
 
54
  print(save_file_path) # Output will be something like "results_2023-08-20T12-34-56.txt"
 
56
  try:
57
  # Sending a GET request
58
  r = requests.get(url, allow_redirects=True)
59
+ r.raise_for_status() # Raises an HTTPError if the HTTP request returned an unsuccessful status code
60
 
61
  # Writing the content to the specified file
62
  with open(save_file_path, 'wb') as file:
63
  file.write(r.content)
64
+
65
  print(f"Successfully downloaded file: {save_file_path}")
66
+ except requests.ConnectionError as e:
67
  print(f"Failed to connect to the URL: {url}")
68
+ raise e
69
  except requests.HTTPError as e:
70
  print(f"HTTP error occurred: {e}")
71
+ raise e
72
+ except FileNotFoundError as e:
73
  print(f"File not found at path: {save_file_path}")
74
+ raise e
75
  except Exception as e:
76
  print(f"An unexpected error occurred: {e}")
77
+ raise e
78
 
79
  return None
80
 
81
 
82
+
83
  @staticmethod
84
  def single_file_pipeline(url, filename):
85
  DetailsDataProcessor.download_file(url, filename)
test_details_data_processing.py CHANGED
@@ -20,6 +20,15 @@ class TestDetailsDataProcessor(unittest.TestCase):
20
  self.assertTrue(os.path.exists('test.html'))
21
  os.remove('test.html')
22
 
 
 
 
 
 
 
 
 
 
23
  def test_build_url(self):
24
  test_cases = [
25
  ('results/64bits/LexPodLM-13B/results_2023-07-25T13:41:51.227672.json',
 
20
  self.assertTrue(os.path.exists('test.html'))
21
  os.remove('test.html')
22
 
23
+
24
+ # there is a file path that results in a 404 error.
25
+ # create a test replicate that error
26
+ def test_download_file_404(self):
27
+ file_path_with_error = 'results/shaohang/Sparse0.5_OPT-1.3/results_2023-07-19T19:10:31.005235.json'
28
+ url = self.processor.build_url(file_path_with_error)
29
+ DetailsDataProcessor.download_file(url, 'test_file_please_remove')
30
+
31
+
32
  def test_build_url(self):
33
  test_cases = [
34
  ('results/64bits/LexPodLM-13B/results_2023-07-25T13:41:51.227672.json',