Skip to content

Commit

Permalink
Update test (#87)
Browse files Browse the repository at this point in the history
* Update test

* Enhancing Tests

---------

Co-authored-by: Fedor Batonogov <f.batonogov@yandex.ru>
  • Loading branch information
github-actions[bot] and batonogov committed May 21, 2024
1 parent 9795809 commit fb13834
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
25 changes: 16 additions & 9 deletions build-and-test.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#!/bin/bash

if [ -z $1 ];
then
if [ -z $1 ]; then
echo "Enter dockerfile name"
else
{ # try
docker build -f $1 -t pyinstaller_test . && \
docker run -v "$(pwd)/test:/src/" pyinstaller_test "pyinstaller main.py --onefile"
} || { # catch
podman build -f $1 -t pyinstaller_test . && \
podman run -v "$(pwd)/test:/src/" pyinstaller_test "pyinstaller main.py --onefile"
exit 1
fi

build_and_run() {
local build_cmd=$1
local run_cmd=$2
local dockerfile=$3

$build_cmd -f $dockerfile -t pyinstaller_test . && \
$run_cmd -v "$(pwd)/test:/src/" pyinstaller_test "pyinstaller main.py --onefile"
}

# Try with Docker
if ! build_and_run "docker build" "docker run" $1; then
# If Docker fails, try with Podman
build_and_run "podman build" "podman run" $1
fi
39 changes: 37 additions & 2 deletions test/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
import logging
import random
import time
from datetime import datetime

import requests

get = requests.get("https://api.github.com")
print(get)

def check_requests():
try:
response = requests.get("https://api.github.com")
response.raise_for_status() # Проверка на успешный статус
print(f"Response Status Code: {response.status_code}")
print(f"Response Content: {response.json()}")
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except Exception as err:
print(f"Other error occurred: {err}")


def log_request():
logging.basicConfig(level=logging.INFO)
logging.info(f"Request made at {datetime.now()}")


def simulate_delay():
delay = random.uniform(1, 3)
print(f"Simulating delay of {delay:.2f} seconds")
time.sleep(delay)


def main():
log_request()
simulate_delay()
check_requests()


if __name__ == "__main__":
main()

0 comments on commit fb13834

Please sign in to comment.