From 3e4a20136acb049a405b0da5fd1042263fbb5cb5 Mon Sep 17 00:00:00 2001 From: Vitaly Bogomolov Date: Wed, 4 Mar 2026 17:09:52 +0400 Subject: [PATCH 1/6] step --- pipeline_csv/integrity/__init__.py | 1 + pipeline_csv/integrity/i18n.py | 50 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 pipeline_csv/integrity/__init__.py create mode 100644 pipeline_csv/integrity/i18n.py diff --git a/pipeline_csv/integrity/__init__.py b/pipeline_csv/integrity/__init__.py new file mode 100644 index 0000000..0b9a13c --- /dev/null +++ b/pipeline_csv/integrity/__init__.py @@ -0,0 +1 @@ +"""Pipeline defects danger calculation.""" diff --git a/pipeline_csv/integrity/i18n.py b/pipeline_csv/integrity/i18n.py new file mode 100644 index 0000000..e7c2ad2 --- /dev/null +++ b/pipeline_csv/integrity/i18n.py @@ -0,0 +1,50 @@ +"""Localization stuff.""" + + +class Lang: + """Embedded languages for localize explain text.""" + + Ru = 'ru' + + +def fake_gettext(text, context): + """Translate text in given context.""" + if isinstance(context.is_explain, dict): + return context.is_explain.get(text, text) + + return text + + +def read_item(sign, line, inp): + """Read multiline text item from given start line and input. + + Return tuple from item and last read line. + """ + item = [line.strip().split(sign)[1].strip('"')] + line = next(inp).strip() + while line.startswith('"'): + item.append(line.strip('"')) + line = next(inp).strip() + + return (''.join(item), line) + + +def read_pair(line, inp): + """Read and return pair msgid, msgstr from given start line and input.""" + msgid, line = read_item('msgid ', line, inp) + msgstr, line = read_item('msgstr ', line, inp) + + return (msgid, msgstr) + + +def load_po(file_name): + """Load data from given po file and return it as dict.""" + data = {} + with open(file_name, 'rt', encoding='utf-8') as inp: + for line in inp: + if line.startswith('msgid '): + msgid, msgstr = read_pair(line, inp) + if msgid and msgstr: + data[msgid] = msgstr + + return data From 39139a852925ffc07dc261bc5c63721cde382048 Mon Sep 17 00:00:00 2001 From: Vitaly Bogomolov Date: Wed, 4 Mar 2026 17:21:34 +0400 Subject: [PATCH 2/6] step --- fixtures/ru.po | 249 +++++++++++++++++++++++++ tests/test/test_integrity/__init__.py | 6 + tests/test/test_integrity/test_i18n.py | 16 ++ 3 files changed, 271 insertions(+) create mode 100644 fixtures/ru.po create mode 100644 tests/test/test_integrity/__init__.py create mode 100644 tests/test/test_integrity/test_i18n.py diff --git a/fixtures/ru.po b/fixtures/ru.po new file mode 100644 index 0000000..0ec7bc9 --- /dev/null +++ b/fixtures/ru.po @@ -0,0 +1,249 @@ +# Russian translations for PROJECT. +# Copyright (C) 2023 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2023. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2023-03-01 15:29+0400\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language: ru\n" +"Language-Team: ru \n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.11.0\n" + +#: pipeline_integrity/method/asme/b31g_1991.py:51 +msgid "The relative defect depth == defect depth / pipe wall thickness * 100%." +msgstr "Относительная глубина дефекта == глубина / толщина стенки * 100%." + +#: pipeline_integrity/method/asme/b31g_1991.py:60 +#, python-format +msgid "The relative defect depth less than {}% from wall thickness." +msgstr "Относительная глубина дефекта меньше {}% толщины стенки." + +#: pipeline_integrity/method/asme/b31g_1991.py:63 +#: pipeline_integrity/method/asme/b31g_1991.py:86 +#: pipeline_integrity/method/asme/b31g_1991.py:108 +msgid "The defect is not dangerous." +msgstr "Дефект не опасен." + +#: pipeline_integrity/method/asme/b31g_1991.py:70 +#, python-format +msgid "The relative defect depth greater than {}% from wall thickness." +msgstr "Относительная глубина дефекта больше {}% толщины стенки." + +#: pipeline_integrity/method/asme/b31g_1991.py:73 +msgid "The defect needs to be repaired." +msgstr "Дефект нужно ремонтировать." + +#: pipeline_integrity/method/asme/b31g_1991.py:83 +msgid "" +"The length of the defect {} does not exceed the maximum allowable length " +"{}." +msgstr "Длина дефекта {} не превышает максимально допустимую длину {}." + +#: pipeline_integrity/method/asme/b31g_1991.py:95 +msgid "The length of the defect {} exceed the maximum allowable length {}." +msgstr "Длина дефекта {} превышает максимально допустимую длину {}." + +#: pipeline_integrity/method/asme/b31g_1991.py:98 +msgid "It is necessary to calculate the allowable pressure for defect." +msgstr "Необходимо рассчитать допустимое давление для дефекта." + +#: pipeline_integrity/method/asme/b31g_1991.py:105 +msgid "The working pressure {} does not exceed the allowable pressure {}." +msgstr "Рабочее давление {} не превышает допустимое давление {}." + +#: pipeline_integrity/method/asme/b31g_1991.py:114 +msgid "Repair or pressure reduction to {} required." +msgstr "Необходим ремонт или снижение давления до {}." + +#: pipeline_integrity/method/asme/b31g_1991.py:124 +msgid "Parameter B." +msgstr "Параметр B." + +#: pipeline_integrity/method/asme/b31g_1991.py:132 +msgid "The relative defect depth {} less than {}%." +msgstr "Относительная глубина дефекта {} меньше {}%." + +#: pipeline_integrity/method/asme/b31g_1991.py:135 +msgid "Set Parameter B value to {}." +msgstr "Параметр B ghbybvftncz hfdysv {}." + +#: pipeline_integrity/method/asme/b31g_1991.py:141 +msgid "The relative defect depth {} more than {}%." +msgstr "Относительная глубина дефекта {} больше {}%." + +#: pipeline_integrity/method/asme/b31g_1991.py:182 +msgid "Calculation of the maximum allowable defect length." +msgstr "Расчет максимально допустимой длины дефекта." + +#: pipeline_integrity/method/asme/b31g_1991.py:220 +msgid "Calculation of the maximum allowable pressure." +msgstr "Расчет максимально допустимого давления." + +#: pipeline_integrity/method/asme/b31g_1991.py:221 +msgid "Parameter A for defect length {}." +msgstr "Параметр A для дефекта длиной {}." + +#: pipeline_integrity/method/asme/b31g_1991.py:226 +msgid "Design pressure." +msgstr "Расчетное давление." + +#: pipeline_integrity/method/asme/b31g_1991.py:236 +msgid "Parameter A more than 4." +msgstr "Параметр A больше 4." + +#: pipeline_integrity/method/asme/b31g_1991.py:247 +msgid "Parameter A less than 4." +msgstr "Параметр A меньше 4." + +#: pipeline_integrity/method/asme/b31g_1991.py:262 +msgid "Safe pressure {} more than design pressure {}." +msgstr "Безопасное давление {} превышает расчетное давление {}." + +#: pipeline_integrity/method/asme/b31g_1991.py:266 +msgid "Use design pressure {} as maximum allowable pressure." +msgstr "Используем расчетное давление как максимально допустимое давление." + +#: pipeline_integrity/method/asme/b31g_1991.py:271 +msgid "Use safe pressure {} as maximum allowable pressure." +msgstr "Используем безопасное давление как максимально допустимое давление." + +#: pipeline_integrity/method/asme/b31g_2012.py:40 +msgid "Parameter Z = length^2 / (diameter * wallthickness)." +msgstr "Параметр Z = длина^2 / (диаметр * толщина)." + +#: pipeline_integrity/method/asme/b31g_2012.py:56 +msgid "Parameter M = sqrt(1 + 0.8 * Z)." +msgstr "Параметр M = sqrt(1 + 0.8 * Z)." + +#: pipeline_integrity/method/asme/b31g_2012.py:71 +msgid "Parameter Sflow = 1.1 * material_smys." +msgstr "Параметр Sflow = 1.1 * предел_текучести." + +#: pipeline_integrity/method/asme/b31g_2012.py:81 +msgid "Parameter Sflow > material SMTS." +msgstr "Параметр Sflow > предела прочности при растяжении материала." + +#: pipeline_integrity/method/asme/b31g_2012.py:82 +msgid "Use material SMTS as Sflow = {}." +msgstr "Используем предел прочности при растяжении материала как параметр Sflow." + +#: pipeline_integrity/method/asme/b31g_2012.py:94 +msgid "Calculate failure stress level by the classic way." +msgstr "Вычисляем величину напряжения разрыва классическим методом." + +#: pipeline_integrity/method/asme/b31g_2012.py:107 +msgid "Parameter Z = {} <= 20." +msgstr "Параметр Z = {} <= 20." + +#: pipeline_integrity/method/asme/b31g_2012.py:108 +msgid "" +"Failure stress level = Sflow * (1 - 2/3 * (depth / wallthickness)) / (1 -" +" 2/3 * (depth / wallthickness) / M)." +msgstr "" +"Напряжение разрыва = Sflow * (1 - 2/3 * (глубина / толщина)) / (1 - 2/3 *" +" (глубина / толщина) / M)." + +#: pipeline_integrity/method/asme/b31g_2012.py:130 +msgid "Parameter Z = {} > 20." +msgstr "Параметр Z = {} > 20." + +#: pipeline_integrity/method/asme/b31g_2012.py:131 +msgid "Failure stress level = Sflow * (1 - depth / wallthickness)." +msgstr "Напряжение разрыва = Sflow * (1 - глубина / толщина)." + +#: pipeline_integrity/method/asme/b31g_2012.py:145 +msgid "Calculate failure stress level by the modified way." +msgstr "Вычисляем величину напряжения разрыва модифицированным методом." + +#: pipeline_integrity/method/asme/b31g_2012.py:155 +msgid "Parameter Z = {} <= 50." +msgstr "Параметр Z = {} <= 50." + +#: pipeline_integrity/method/asme/b31g_2012.py:156 +msgid "Parameter M = sqrt(1 + 0.6275 * Z - 0.003375 * Z^2)" +msgstr "Параметр M = sqrt(1 + 0.6275 * Z - 0.003375 * Z^2)" + +#: pipeline_integrity/method/asme/b31g_2012.py:166 +msgid "Parameter Z = {} > 50." +msgstr "Параметр Z = {} > 50." + +#: pipeline_integrity/method/asme/b31g_2012.py:167 +msgid "Parameter M = 0.032 * Z + 3.3" +msgstr "Параметр M = 0.032 * Z + 3.3" + +#: pipeline_integrity/method/asme/b31g_2012.py:177 +msgid "" +"Failure stress level = Sflow * (1 - 0.85 * (depth / wallthickness)) / (1 " +"- 0.85 * (depth / wallthickness) / M)." +msgstr "" +"Напряжение разрыва = Sflow * (1 - 0.85 * (глубина / толщина)) / (1 - 0.85" +" * (глубина / толщина) / M)." + +#: pipeline_integrity/method/asme/b31g_2012.py:207 +msgid "Failure pressure = 2 * stress_fail * wallthickness / diameter." +msgstr "Давление разрыва = 2 * stress_fail * толщина / диаметр." + +#: pipeline_integrity/method/asme/b31g_2012.py:220 +msgid "modified" +msgstr "модифицированный" + +#: pipeline_integrity/method/asme/b31g_2012.py:220 +msgid "classic" +msgstr "классический" + +#: pipeline_integrity/method/asme/b31g_2012.py:222 +msgid "Calculate ERF by {} {}." +msgstr "Вычисляем КБД по {} {}." + +#: pipeline_integrity/method/asme/b31g_2012.py:229 +msgid "ERF = pipe_maop / press_fail." +msgstr "КБД = рабочее_давление / давление_разрыва." + +#: pipeline_integrity/method/asme/b31g_2012.py:246 +msgid "Repair required immediately, years to repair: 0." +msgstr "Необходим ремонт, лет до ремонта: 0." + +#: pipeline_integrity/method/asme/b31g_2012.py:257 +msgid "Repair is not required at the moment, calculate the time before repair." +msgstr "На данный момент ремонт не требуется, вычисляем время до ремонта." + +#: pipeline_integrity/method/asme/b31g_2012.py:259 +msgid "" +"With corrosion rate {} mm/year, pipe wall {} and depth {} a through hole " +"is formed after years: {}." +msgstr "При скорости коррозии {} мм/год, толщине стенки {} и глубине дефекта {}, сквозной дефект образуется через лет: {}." + +#: pipeline_integrity/method/asme/b31g_2012.py:277 +msgid "But even a through defect does not require repair." +msgstr "Но даже сквозной дефект не нуждается в ремонте." + +#: pipeline_integrity/method/asme/b31g_2012.py:278 +msgid "ERF = {}. Use special value for years: 777." +msgstr "КБД = {}. Используем специальное значение 777 для годов до ремонта." + +#: pipeline_integrity/method/asme/b31g_2012.py:288 +msgid "" +"Calculating the year in which the corrosion growth of the defect will " +"require repair." +msgstr "Вычисляем через сколько лет дефект потребует ремонта при заданной скорости коррозии." + +#: pipeline_integrity/method/asme/b31g_2012.py:307 +#: pipeline_integrity/method/asme/b31g_2012.py:308 +msgid "Years: {} ERF: {}." +msgstr "Года: {} КБД: {}." + +#: pipeline_integrity/method/asme/b31g_2012.py:309 +msgid "Defect will require repair after years: {}." +msgstr "Дефект нужно будет отремонтировать через лет: {}." + diff --git a/tests/test/test_integrity/__init__.py b/tests/test/test_integrity/__init__.py new file mode 100644 index 0000000..266c487 --- /dev/null +++ b/tests/test/test_integrity/__init__.py @@ -0,0 +1,6 @@ +"""Root class for testing integrity package.""" +from .. import TestIV + + +class TestIntegrity(TestIV): + """Base class for Integrity tests.""" diff --git a/tests/test/test_integrity/test_i18n.py b/tests/test/test_integrity/test_i18n.py new file mode 100644 index 0000000..bb4ce88 --- /dev/null +++ b/tests/test/test_integrity/test_i18n.py @@ -0,0 +1,16 @@ +"""Tests i18n.py file. + +make test T=test_csv/test_i18n.py +""" +from . import TestIntegrity + + +class TestI18n(TestIntegrity): + """File i18n.py.""" + + def test_load_po(self): + """Check load_po function.""" + from pipeline_csv.integrity.i18n import load_po + + data = load_po(self.fixture('ru.po')) + assert len(data) > 1 From cfb31d712bcde79407329a33556a0e23cb0562a1 Mon Sep 17 00:00:00 2001 From: Vitaly Bogomolov Date: Wed, 4 Mar 2026 17:25:03 +0400 Subject: [PATCH 3/6] step --- pipeline_csv/{ => integrity}/material.py | 0 tests/test/test_integrity/test_i18n.py | 2 +- tests/test/{ => test_integrity}/test_material.py | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) rename pipeline_csv/{ => integrity}/material.py (100%) rename tests/test/{ => test_integrity}/test_material.py (70%) diff --git a/pipeline_csv/material.py b/pipeline_csv/integrity/material.py similarity index 100% rename from pipeline_csv/material.py rename to pipeline_csv/integrity/material.py diff --git a/tests/test/test_integrity/test_i18n.py b/tests/test/test_integrity/test_i18n.py index bb4ce88..5750dc5 100644 --- a/tests/test/test_integrity/test_i18n.py +++ b/tests/test/test_integrity/test_i18n.py @@ -1,6 +1,6 @@ """Tests i18n.py file. -make test T=test_csv/test_i18n.py +make test T=test_integrity/test_i18n.py """ from . import TestIntegrity diff --git a/tests/test/test_material.py b/tests/test/test_integrity/test_material.py similarity index 70% rename from tests/test/test_material.py rename to tests/test/test_integrity/test_material.py index 9f591c6..d1fbe03 100644 --- a/tests/test/test_material.py +++ b/tests/test/test_integrity/test_material.py @@ -1,17 +1,17 @@ """Module test_material.py. -make test T=test_material.py +make test T=test_integrity/test_material.py """ -from . import TestIV +from . import TestIntegrity -class TestMaterial(TestIV): +class TestMaterial(TestIntegrity): """Check material.py file.""" @staticmethod def test_material(): """Check PipeMaterial class.""" - from pipeline_csv.material import PipeMaterial + from pipeline_csv.integrity.material import PipeMaterial material = PipeMaterial("Сталь3", 250) assert material.name == "Сталь3" From a6f776753f46e39fd0d54836e1714f393c2c0b3c Mon Sep 17 00:00:00 2001 From: Vitaly Bogomolov Date: Wed, 4 Mar 2026 18:23:25 +0400 Subject: [PATCH 4/6] step --- tests/test/test_integrity/test_i18n.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test/test_integrity/test_i18n.py b/tests/test/test_integrity/test_i18n.py index 5750dc5..ee05601 100644 --- a/tests/test/test_integrity/test_i18n.py +++ b/tests/test/test_integrity/test_i18n.py @@ -5,6 +5,12 @@ from . import TestIntegrity +class MockContext: + """Mocked Context class.""" + + is_explain = None + + class TestI18n(TestIntegrity): """File i18n.py.""" @@ -14,3 +20,9 @@ def test_load_po(self): data = load_po(self.fixture('ru.po')) assert len(data) > 1 + + def test_fgettext(self): + """Check fake_gettext function.""" + from pipeline_csv.integrity.i18n import fake_gettext + + assert fake_gettext('xxx', MockContext()) == 'xxx' From c155bb6e61edddb47c28b238f8a542979cfd88c1 Mon Sep 17 00:00:00 2001 From: Vitaly Bogomolov Date: Wed, 4 Mar 2026 18:37:52 +0400 Subject: [PATCH 5/6] step --- tests/test/test_integrity/test_i18n.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test/test_integrity/test_i18n.py b/tests/test/test_integrity/test_i18n.py index ee05601..6afd933 100644 --- a/tests/test/test_integrity/test_i18n.py +++ b/tests/test/test_integrity/test_i18n.py @@ -8,7 +8,9 @@ class MockContext: """Mocked Context class.""" - is_explain = None + def __init__(self, is_explain=None): + """Make instance.""" + self.is_explain = is_explain class TestI18n(TestIntegrity): @@ -26,3 +28,8 @@ def test_fgettext(self): from pipeline_csv.integrity.i18n import fake_gettext assert fake_gettext('xxx', MockContext()) == 'xxx' + + data = { + 'xxx': 'yyy' + } + assert fake_gettext('xxx', MockContext(is_explain=data)) == 'yyy' From 04d9122ae13413f81608011b42d1a66dc888580a Mon Sep 17 00:00:00 2001 From: vb64 Date: Wed, 4 Mar 2026 22:36:51 +0400 Subject: [PATCH 6/6] step --- bandit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/bandit.yml b/bandit.yml index 271194d..53f2df9 100644 --- a/bandit.yml +++ b/bandit.yml @@ -1,3 +1,4 @@ # Warnings "Use of assert detected" are invalid. # Please disable this pattern for test code. skips: .'B101'. +assert_used: skips: ['*_test.py', '*test_*.py']