Skip to content
Snippets Groups Projects
Commit a88b6f52 authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

#86 Endret modulnavn og funksjonen insert_spaces

parent 66445b0f
No related branches found
No related tags found
1 merge request!50#86 Modul: Autentiseringstavle
Pipeline #78151 failed
......@@ -109,38 +109,23 @@ def get_code_length_needed(number_of_entries):
def insert_spaces(code, interval):
"""Add spaces between code-character each interval.
"""Insert space after every x'th character, x = interval.
Parameters
----------
code : string
Code to add spaces to.
String to add spaces to.
interval : int
Interval for inserting spaces.
Returns
-------
string
Code separated with spaces.
code separated with spaces.
"""
# Choose starting point for separating code with spaces, depending on
# SEPARATE_INTERVAL and CODE_LENGTH being even or odd numbers.
# If code is 1234567 and interval is 3, code will be 1234 567 instead
# of 123 456 7 after space separation.
code_length = len(code)
if (
interval % 2 == 0
and code_length % 2 == 0
or interval % 2 != 0
and code_length % 2 != 0
):
start = interval - 1
else:
start = interval
# Convert to list to add spaces in-between characters
# Convert to list to insert spaces between characters
code = list(code)
for i in range(start, code_length - interval, interval):
for i in range(interval - 1, len(code), interval):
code[i] += " "
return "".join(code)
......@@ -12,23 +12,22 @@ from soitool.modules.module_base import (
)
START_NO_OF_AUTHENTICATION_CODES = 10
CODE_LENGTH = 26
CODE_LENGTH = 25
CODE_CHARACTERS = "ascii" # Has to be 'ascii', 'digits' or 'combo'
# Codes will consist of A-Z if 'ascii', 0-9 if 'digits' and A-Z+0-9 if 'combo'.
ROW_IDENTIFIERS = string.ascii_uppercase # Characters for first column,
# it's length determines maximum number of codes (rows).
SPACE_INTERVAL = 5 # Adds space between sets of characters, 0 => no spaces
# If code is 123456 and interval is 2, code will be 12 34 56
# If code is 1234567 and interval is 2, code will be 123 45 67
HEADLINE_TEXT = "Autentifiseringstavle"
HEADLINE_TEXT = "Autentiseringstavle"
class Meta(type(ModuleBase), type(QTableWidget)):
"""Used as a metaclass to enable multiple inheritance."""
class AuthentificationBoardModule(ModuleBase, QTableWidget, metaclass=Meta):
class AuthenticationBoardModule(ModuleBase, QTableWidget, metaclass=Meta):
"""Modified QTableWidget representing a 'Autentifiseringstavle'.
By default, the widget initializes with a headline, a row-count of
......@@ -171,7 +170,7 @@ class AuthentificationBoardModule(ModuleBase, QTableWidget, metaclass=Meta):
):
self.remove_row()
else:
super(AuthentificationBoardModule, self).keyPressEvent(event)
super(AuthenticationBoardModule, self).keyPressEvent(event)
def add_row(self):
"""Insert row below the selected row and add data."""
......@@ -265,7 +264,7 @@ class AuthentificationBoardModule(ModuleBase, QTableWidget, metaclass=Meta):
@staticmethod
def get_user_friendly_name():
"""Get user-friendly name of module."""
return "Autentifiseringstavle"
return "Autentiseringstavle"
@staticmethod
def get_icon():
......
......@@ -13,8 +13,8 @@ from PySide2.QtWidgets import (
)
from PySide2.QtCore import QSize, Qt
from soitool.modules.module_table import TableModule
from soitool.modules.module_authentification_board import (
AuthentificationBoardModule,
from soitool.modules.module_authentication_board import (
AuthenticationBoardModule,
)
......@@ -23,7 +23,7 @@ from soitool.modules.module_authentification_board import (
# placed here, and the rest of the program will respect them.
MODULE_CHOICES = [
TableModule,
AuthentificationBoardModule,
AuthenticationBoardModule,
]
......
......@@ -5,8 +5,8 @@ from schema import Schema, And, Or
from soitool.soi import SOI
from soitool.compressor import compress, decompress
from soitool.modules.module_table import TableModule
from soitool.modules.module_authentification_board import (
AuthentificationBoardModule,
from soitool.modules.module_authentication_board import (
AuthenticationBoardModule,
)
# Valid schema for serialized SOI
......@@ -226,7 +226,7 @@ def import_soi(file_path):
data = module["data"]
modules.append(
{
"widget": AuthentificationBoardModule(size, data),
"widget": AuthenticationBoardModule(size, data),
"meta": module["meta"],
}
)
......
"""Test AuthentificationBoardModule."""
"""Test AuthenticationBoardModule."""
import unittest
from PySide2 import QtGui
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import Qt
from PySide2.QtTest import QTest
from soitool.modules.module_authentification_board import (
AuthentificationBoardModule,
from soitool.modules.module_authentication_board import (
AuthenticationBoardModule,
START_NO_OF_AUTHENTICATION_CODES,
HEADLINE_TEXT,
ROW_IDENTIFIERS,
......@@ -19,12 +19,12 @@ else:
app = QtGui.qApp
class TestDefaultAuthentificationBoardModule(unittest.TestCase):
"""TestCase for AuthentificationBoardModule."""
class TestDefaultAuthenticationBoardModule(unittest.TestCase):
"""TestCase for AuthenticationBoardModule."""
def setUp(self):
"""Create new AuthentificationBoardModule."""
self.module = AuthentificationBoardModule()
"""Create new AuthenticationBoardModule."""
self.module = AuthenticationBoardModule()
def test_default_module(self):
"""Test that module is initialized properly."""
......@@ -148,11 +148,11 @@ class TestDefaultAuthentificationBoardModule(unittest.TestCase):
self.assertTrue(soi.module_name_taken(module_name))
class TestAuthentificationBoardModuleFromData(unittest.TestCase):
"""TestCase for initializing AuthentificationBoardModule from data."""
class TestAuthenticationBoardModuleFromData(unittest.TestCase):
"""TestCase for initializing AuthenticationBoardModule from data."""
def test_create_from_data(self):
"""Test creating AuthentificationBoardModule from data."""
"""Test creating AuthenticationBoardModule from data."""
test_data = [
"Headline text",
["A", "0", "TEST CODE ONE"],
......@@ -160,7 +160,7 @@ class TestAuthentificationBoardModuleFromData(unittest.TestCase):
]
test_size = {"width": 100, "height": 100}
module = AuthentificationBoardModule(size=test_size, data=test_data)
module = AuthenticationBoardModule(size=test_size, data=test_data)
# Assert module contains expected data
self.assertEqual(module.item(0, 0).text(), "Headline text")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment