Skip to content

Commit 96a5aa7

Browse files
committed
changes
1 parent 0ed00ca commit 96a5aa7

3 files changed

Lines changed: 19 additions & 233 deletions

File tree

‎main.py‎

Lines changed: 6 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,8 @@
1-
"""
2-
ETL-Query script
3-
"""
1+
# main.py
42

5-
import sys
6-
import argparse
7-
from mylib.extract import extract
8-
from mylib.transform_load import load
9-
from mylib.query import (
10-
create,
11-
read,
12-
update,
13-
delete,
14-
run_query,
15-
)
3+
import lib # Import the library module
164

17-
18-
def handle_arguments(args):
19-
"""add action based on inital calls"""
20-
parser = argparse.ArgumentParser(description="ETL-Query script")
21-
parser.add_argument(
22-
"action",
23-
choices=[
24-
"extract",
25-
"transform_load",
26-
"create",
27-
"read",
28-
"update",
29-
"delete",
30-
"run_query",
31-
],
32-
)
33-
args = parser.parse_args(args[:1])
34-
print(args.action)
35-
if args.action == "update":
36-
37-
parser.add_argument("record_id", type=int)
38-
parser.add_argument("Flavour")
39-
parser.add_argument("Calories", type=int)
40-
parser.add_argument("Total_Fat_g", type=float)
41-
parser.add_argument("Trans_Fat_g", type=float)
42-
parser.add_argument("Carbohydrates_g", type=int)
43-
parser.add_argument("Sugars_g", type=int)
44-
parser.add_argument("Protein_g", type=float)
45-
parser.add_argument("Size")
46-
47-
if args.action == "create":
48-
49-
parser.add_argument("Flavour")
50-
parser.add_argument("Calories", type=int)
51-
parser.add_argument("Total_Fat_g", type=float)
52-
parser.add_argument("Trans_Fat_g", type=float)
53-
parser.add_argument("Carbohydrates_g", type=int)
54-
parser.add_argument("Sugars_g", type=int)
55-
parser.add_argument("Protein_g", type=float)
56-
parser.add_argument("Size")
57-
58-
if args.action == "run_query":
59-
parser.add_argument("query")
60-
61-
if args.action == "delete":
62-
parser.add_argument("record_id", type=int)
63-
64-
# parse again with ever
65-
return parser.parse_args(sys.argv[1:])
66-
67-
68-
def main():
69-
"""handles all the cli commands"""
70-
args = handle_arguments(sys.argv[1:])
71-
72-
if args.action == "extract":
73-
print("Extracting data...")
74-
extract()
75-
elif args.action == "transform_load":
76-
print("Transforming data...")
77-
load()
78-
elif args.action == "update_record":
79-
update(
80-
args.record_id,
81-
args.Flavour,
82-
args.Calories,
83-
args.Total_Fat_g,
84-
args.Trans_Fat_g,
85-
args.Carbohydrates_g,
86-
args.Sugars_g,
87-
args.Protein_g,
88-
args.Size,
89-
)
90-
elif args.action == "delete":
91-
delete(args.record_id)
92-
elif args.action == "create":
93-
create(
94-
args.Flavour,
95-
args.Calories,
96-
args.Total_Fat_g,
97-
args.Trans_Fat_g,
98-
args.Carbohydrates_g,
99-
args.Sugars_g,
100-
args.Protein_g,
101-
args.Size,
102-
)
103-
elif args.action == "run_query":
104-
run_query(args.query)
105-
elif args.action == "read":
106-
data = read()
107-
print(data)
108-
else:
109-
print(f"Unknown action: {args.action}")
110-
111-
112-
if __name__ == "__main__":
113-
main()
5+
if __name__ == '__main__':
6+
number = 5 # Change this to the desired number
7+
result = lib.factorial(number)
8+
print(f"Factorial of {number} is {result}")

‎mylib/lib.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# lib.py
2+
13
def factorial(n):
24
if n == 0:
35
return 1
46
else:
5-
return n * factorial(n - 1)
7+
return n * factorial(n - 1)

‎test_main.py‎

Lines changed: 10 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,14 @@
1-
"""
2-
Test goes here
1+
# test_main.py
32

4-
"""
3+
import lib # Import the library module
4+
import unittest
55

6-
import subprocess
6+
class TestFactorialFunction(unittest.TestCase):
77

8+
def test_factorial(self):
9+
self.assertEqual(lib.factorial(0), 1)
10+
self.assertEqual(lib.factorial(5), 120)
11+
# Add more test cases here
812

9-
def test_extract():
10-
"""tests extract()"""
11-
result = subprocess.run(
12-
["python", "main.py", "extract"],
13-
capture_output=True,
14-
text=True,
15-
check=True,
16-
)
17-
assert result.returncode == 0
18-
assert "Extracting data..." in result.stdout
19-
20-
21-
def test_transform_load():
22-
"""tests transfrom_load"""
23-
result = subprocess.run(
24-
["python", "main.py", "transform_load"],
25-
capture_output=True,
26-
text=True,
27-
check=True,
28-
)
29-
assert result.returncode == 0
30-
assert "Transforming data..." in result.stdout
31-
32-
33-
def test_update():
34-
"""tests update"""
35-
result = subprocess.run(
36-
[
37-
"python",
38-
"main.py",
39-
"update",
40-
"1",
41-
"Butterscotch",
42-
"114",
43-
"7.5",
44-
"0.4",
45-
"25",
46-
"18",
47-
"2.2",
48-
"kids70g",
49-
],
50-
capture_output=True,
51-
text=True,
52-
check=True,
53-
)
54-
assert result.returncode == 0
55-
56-
57-
def test_delete():
58-
"""tests delete"""
59-
result = subprocess.run(
60-
["python", "main.py", "delete", "1"],
61-
capture_output=True,
62-
text=True,
63-
check=True,
64-
)
65-
assert result.returncode == 0
66-
67-
68-
def test_create():
69-
"""tests create"""
70-
result = subprocess.run(
71-
[
72-
"python",
73-
"main.py",
74-
"create",
75-
"Butterscotch",
76-
"114",
77-
"7.5",
78-
"0.4",
79-
"25",
80-
"18",
81-
"2.2",
82-
"kids70g",
83-
],
84-
capture_output=True,
85-
text=True,
86-
check=True,
87-
)
88-
assert result.returncode == 0
89-
90-
91-
def test_run_query():
92-
"""tests run_query"""
93-
result = subprocess.run(
94-
[
95-
"python",
96-
"main.py",
97-
"run_query",
98-
"SELECT * FROM baskin_icecream WHERE Flavour = 'Butterscotch'",
99-
],
100-
capture_output=True,
101-
text=True,
102-
check=True,
103-
)
104-
assert result.returncode == 0
105-
106-
107-
def test_read():
108-
"""tests read"""
109-
result = subprocess.run(
110-
["python", "main.py", "read"],
111-
capture_output=True,
112-
text=True,
113-
check=True,
114-
)
115-
assert result.returncode == 0
116-
117-
118-
if __name__ == "__main__":
119-
test_extract()
120-
test_transform_load()
121-
test_create()
122-
test_read()
123-
test_update()
124-
test_delete()
125-
test_run_query()
13+
if __name__ == '__main__':
14+
unittest.main()

0 commit comments

Comments
 (0)