working on it ...

Filters

Explore Public Snippets

Sort by

Found 5 snippets

    public by huanshuai  2725  2  5  0

    Makefile for Python App

    VENV=./venv
    PYTHON=$(VENV)/bin/python
    PIP=$(VENV)/bin/pip
     
    PACKAGE=rtlogclient
    SETUP=./setup.py
    REQUIREMENTS=./requirements.txt
    TEST_DIR=./tests/
     
    .PHONY: all update_tools install_requirements install develop test
     
    usage:
    	@echo use `make [target]` to build project.
     
    update_tools:
    	$(PIP) install --upgrade setuptools pip
     
    install_requirements: update_tools $(REQUIREMENTS)
    	$(PIP) install -r $(REQUIREMENTS)
     
    install: install_requirements $(SETUP)
    	$(PYTHON) $(SETUP) install
     
    develop: install_requirements $(SETUP)
    	$(PYTHON) $(SETUP) develop
     
    test: $(SETUP) $(TEST_DIR)
    	$(PYTHON) $(SETUP) test --pytest-args='--cov $(PACKAGE) $(TEST_DIR)'
                

    public by huanshuai  219444  1  6  1

    Get logging config and start logging in Python

    import logging
    import os.path
    
    SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
    
    def main():
        log_path = os.path.join(SCRIPT_DIR, 'logging.conf')
        logging.config.fileConfig(log_path, disable_existing_loggers=False)
        logger.info("start logging!")
    

    public by huanshuai  2336  1  6  0

    Common INI file for logging module in Python

    [loggers]
    keys=root
    
    [handlers]
    keys=consoleHandler
    
    [formatters]
    keys=simpleFormatter
    
    [logger_root]
    level=INFO
    handlers=consoleHandler
    
    [handler_consoleHandler]
    class=StreamHandler
    level=DEBUG
    formatter=simpleFormatter
    args=(sys.stdout,)
    
    [formatter_simpleFormatter]
    format=%(name)s [%(asctime)s] %(levelname)s: %(message)s
    datefmt=

    public by huanshuai  4514  3  6  0

    Flask Web Test using Selenium

    import time
    from unittest import TestCase
    from flask import url_for
    from selenium import webdriver
    
    from learnpython.app import app
    
    class TestViewsWithSelenium(TestCase):
        def setUp(self):
            self.browser = webdriver.Firefox()
            app.testing = True
            self._ctx = app.test_request_context()
            self._ctx.push()
    
        def tearDown(self):
            self._ctx.pop()
            self.browser.quit()
    
        def test_index(self):
            index_url = self.url('page', name='index')
    
            self.browser.get(self.url('/'))
            self.assertEqual(self.browser.current_url, index_url)
            time.sleep(1)
    
            element = self.browser.find_element_by_link_text('Learn Python')
            self.assertEqual(element.get_attribute('href'), index_url)
    
        def test_static(self):
            self.browser.get(self.url('static', filename='css/screen.css'))
            self.browser.get(self.url('static', filename='does_not_exists.exe'))

    public by huanshuai  233088  1  6  0

    Flask demo: hello world

    from flask import Flask, render_template
    app = Flask(__name__)
    
    
    @app.route('/', methods=['GET'])
    def index():
        return render_template('index.html')
    
    @app.route("/hello")
    def hello():
        return "Welcome to Python Flask App!"
    
    
    if __name__ == "__main__":
        app.run()            

    List Complete ( 5 snippets total )

    • Public Snippets
    • Channels Snippets