Skip to content

Commit 34849db

Browse files
committed
CLI support to run test files
1 parent 2601cb9 commit 34849db

File tree

8 files changed

+66
-13
lines changed

8 files changed

+66
-13
lines changed

binnacle/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
command_run, command_mode, command_node, command_ssh_user,
55
command_ssh_sudo, command_ssh_pem_file, command_port, command_container
66
)
7-
from binnacle.plugins.compare import compare_equal, compare_not_equal
7+
from binnacle.plugins.compare import (compare_equal,
8+
compare_not_equal)

binnacle/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=0.7.0
1+
VERSION="0.7.0"

custom_entry.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import argparse
2+
import sys
3+
import subprocess
4+
import pytest
5+
import os
6+
7+
def parse_args():
8+
9+
parser = argparse.ArgumentParser(description="CLI tool to run selected files")
10+
parser.add_argument('-v',
11+
"--verbose",
12+
action='count',
13+
default =0,
14+
help='increase verbosity -v, -vv,-vvv')
15+
parser.add_argument('paths',
16+
nargs='+', # Accepts zero or more positional arguments
17+
help='Names of the test files to run or test directory')
18+
return parser.parse_args()
19+
20+
21+
def run_files(file_name,env):
22+
print(f"\n[Running] {file_name}")
23+
subprocess.run([sys.executable, file_name], env=env, check=True)
24+
25+
26+
def run_directory(direc,env):
27+
for root, _, files in os.walk(direc):
28+
for file in files:
29+
if file.endswith('.py'):
30+
full_path = os.path.join(root, file)
31+
run_files(full_path,env)
32+
33+
34+
def main():
35+
36+
args = parse_args()
37+
38+
env = os.environ.copy()
39+
if args.verbose:
40+
env["DEBUG"] = "true" #set env variable
41+
42+
for path in args.paths:
43+
44+
if os.path.isfile(path) and path.endswith('.py'):
45+
run_files(path,env)
46+
elif os.path.isdir(path):
47+
run_directory(path,env)
48+
else:
49+
print("File or directory does not exist")
50+

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
"Programming Language :: Python :: 3",
2222
"Programming Language :: Python :: 3 :: Only"
2323
],
24+
entry_points={
25+
'console_scripts':[
26+
'binnacle=custom_entry:main',
27+
],
28+
},
2429
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#mode 3: docker
44
command_mode("docker")
5-
command_container("server1")
5+
command_container("server1") #Your docker container name
66

77
# Check if report is generated or a file exists in a container
88
command_run("echo 'Hello World!' > /root/reports.txt")
99
command_run("stat /root/reports.txt") #report exixts
1010
command_run("stat /root/reports1.txt 2>/dev/null && echo 'File exists' || echo 'File does not exist'") #report1 does not exixt
11-
11+
show_summary()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
validated_json('{"name": 100}')
55
command_run("ls /tmp")
66
command_run("stat /home/ubuntu/reports.pdf")
7-
7+
show_summary()
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#mode2: ssh
44
command_mode("ssh")
5-
command_node("192.168.29.65")
5+
command_node("192.168.29.65") #your VM IP
66
command_ssh_user("test1")
77
command_ssh_sudo(False)
88
command_ssh_pem_file("~/.ssh/id_rsa")
@@ -12,5 +12,3 @@
1212
# unless command_node("local")
1313
command_run("cat /tmp/hello")
1414
show_summary()
15-
16-
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from binnacle import *
2+
import os
23

4+
5+
#run server setup in server.py
36
http_base_url("http://localhost:5001")
47

58
# Without API Key
@@ -13,13 +16,9 @@
1316
http_set_header("x-api-key", "user_26a5fa8c7d8ad3729d218bcecf38c3aa9a7d4e40106072b4fd3f313af5c0682f")
1417
data = http_get("/api/v1/folders")
1518
debug(data)
16-
folders = validated_json(data)
17-
18-
#compare_equal(len(folders), 4)
19-
#compare_not_equal(100, 100)
2019

20+
folders = validated_json(data)
2121
validated_json('{"name": 100}')
2222

23-
# command_run("ls /tmp")
2423

2524
show_summary()

0 commit comments

Comments
 (0)