Skip to content

Commit

Permalink
GitLab CI
Browse files Browse the repository at this point in the history
Signed-off-by: Javinator9889 <javialonso007@hotmail.es>
  • Loading branch information
Javinator9889 committed Sep 20, 2019
1 parent 2831b23 commit 530952f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
31 changes: 31 additions & 0 deletions .gitlab-ci.yml
@@ -0,0 +1,31 @@
# https://hub.docker.com/r/library/python/tags/
image: python:latest

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
paths:
- .cache/pip
- venv/

before_script:
- python -V # Print out python version for debugging
- pip install pylint
- pip install -R requirements.txt
- cd YouTubeMDBot

test:pylint:
script:
- pylint --ignored-classes=_socketobject *.py

test:
script:
- python -m unittest $(pwd)/YouTubeMDBot/tests/*.py
4 changes: 0 additions & 4 deletions YouTubeMDBot/tests/__main__.py

This file was deleted.

18 changes: 16 additions & 2 deletions YouTubeMDBot/tests/downloader.py
@@ -1,10 +1,15 @@
import threading
import unittest
from time import sleep

from YouTubeMDBot.downloader import YouTubeDownloader


class DownloadTest(unittest.TestCase):
_elements = 0
_max = 0
_lock = threading.Lock()

def test_multithread_download(self):
yt1 = YouTubeDownloader(url="https://www.youtube.com/watch?v=Inm-N5rLUSI")
yt2 = YouTubeDownloader(url="https://www.youtube.com/watch?v=-_ZwpOdXXcA")
Expand All @@ -15,17 +20,26 @@ def test_multithread_download(self):
t3 = threading.Thread(target=self.write_to_file, args=(yt3, "v3.m4a",))
t4 = threading.Thread(target=self.write_to_file, args=(yt4, "v4.m4a",))

self._max = 4

t1.start()
t2.start()
t3.start()
t4.start()

@staticmethod
def write_to_file(yt: YouTubeDownloader, name: str):
while self._elements < self._max:
sleep(1)

def barrier(self):
with self._lock:
self._elements += 1

def write_to_file(self, yt: YouTubeDownloader, name: str):
_, data = yt.download()
print(name + " downloaded")
with open(name, "wb") as f:
f.write(data)
self.barrier()


if __name__ == '__main__':
Expand Down

0 comments on commit 530952f

Please sign in to comment.