Skip to content

Instantly share code, notes, and snippets.

@DavidPiper94
DavidPiper94 / mypy_example_2.py
Last active September 24, 2019 14:25
Example code for article about mypy - Example 2
from typing import List, Optional
def position_of(string: str, list: List[str]) -> Optional[int]:
if not string in list: return None
return list.index(string)
@DavidPiper94
DavidPiper94 / mypy_example_1.py
Last active September 24, 2019 14:22
Example code for article about mypy - Example 1
def concat(lhs: str, rhs: str) -> str:
return lhs + rhs
@DavidPiper94
DavidPiper94 / python_unittest_testrunner.py
Last active September 24, 2019 14:23
Example code for article about unit tests - Testrunner
import unittest
loader = unittest.TestLoader()
start_dir = '.'
suite = loader.discover(start_dir)
runner = unittest.TextTestRunner()
runner.run(suite)
@DavidPiper94
DavidPiper94 / python_unittest_example.py
Last active September 24, 2019 14:24
Example code for article about unit tests - ExampleTest
import unittest
class ExampleTests(unittest.TestCase):
def test_add(self):
expectation = 4
actual = 2 + 2
self.assertEqual(
expectation,
actual,
@DavidPiper94
DavidPiper94 / python_unittest_output.txt
Last active September 24, 2019 14:24
Example code for article about unit tests - Output
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
@DavidPiper94
DavidPiper94 / python_unittest_executable.py
Last active September 24, 2019 14:25
Example code for article about unit tests - Executable
if __name__ == '__main__':
unittest.main()
@DavidPiper94
DavidPiper94 / python_pipenv_example_pipfile.txt
Created August 5, 2019 05:15
Example code for article about pipenv
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
numpy = "*"
@DavidPiper94
DavidPiper94 / logen_groupingconverter_1.py
Created September 7, 2019 09:12
Example code for article about adding a new converter to Logen - Imports of GroupingConverter
# 1
from ..converter.ConverterInterface import ConverterInterface as Base
# 2
from ..model.IntermediateEntry import IntermediateEntry
from ..model.IntermediateLanguage import IntermediateLanguage
from ..model.IntermediateLocalization import IntermediateLocalization
from ..model.LocalizationFile import LocalizationFile
#3
@DavidPiper94
DavidPiper94 / logen_groupingconverter_2.py
Created September 7, 2019 09:14
Example code for article about adding a new converter to Logen - Declaration of GroupingConverter
# Declaring class and inheriting from base converter.
class GroupingConverter(Base):
@DavidPiper94
DavidPiper94 / logen_groupingconverter_3.py
Created September 7, 2019 09:14
Example code for article about adding a new converter to Logen - fileExtension of GroupingConverter
def fileExtension(self) -> str:
# This converter will output a simple txt-file.
return ".txt"