adress mypy and flake8 findings

main
svalouch 5 years ago
parent 5731fcfd48
commit 42bf2dc276

@ -158,6 +158,7 @@ def validate_metadata_property_name(name: str) -> None:
if not METADATA_PROPERTY_NAME_RE.match(name): if not METADATA_PROPERTY_NAME_RE.match(name):
raise ValidationError('property name does not match') raise ValidationError('property name does not match')
def validate_property_value(value: str) -> None: def validate_property_value(value: str) -> None:
''' '''
Validates the value of a property. This works for both native properties, where the driver will tell us if the Validates the value of a property. This works for both native properties, where the driver will tell us if the

@ -10,7 +10,7 @@ import shutil
import subprocess import subprocess
from .exceptions import DatasetNotFound, PropertyNotFound from .exceptions import DatasetNotFound, PropertyNotFound
from .types import Property, Dataset from .types import Dataset, Property, PropertySource
from .validation import ( from .validation import (
validate_dataset_path, validate_dataset_path,
validate_pool_name, validate_pool_name,
@ -164,7 +164,9 @@ class ZFSCli(ZFS):
if is_metadata: if is_metadata:
namespace = prop_name.split(':')[0] namespace = prop_name.split(':')[0]
return Property(key=prop_name, value=prop_value, source=prop_source, namespace=namespace) property_source = PropertySource.from_string(prop_source)
return Property(key=prop_name, value=prop_value, source=property_source, namespace=namespace)
def _get_properties(self, dataset: str, include_metadata: bool = False) -> List[Property]: def _get_properties(self, dataset: str, include_metadata: bool = False) -> List[Property]:
''' '''
@ -182,11 +184,12 @@ class ZFSCli(ZFS):
for line in proc.stdout.split('\n'): for line in proc.stdout.split('\n'):
if line: if line:
_, prop_name, prop_value, prop_source = line.strip().split('\t') _, prop_name, prop_value, prop_source = line.strip().split('\t')
property_source = PropertySource.from_string(prop_source)
if ':' in prop_name: if ':' in prop_name:
if include_metadata: if include_metadata:
namespace = prop_name.split(':')[0] namespace = prop_name.split(':')[0]
prop_name = prop_name.lstrip(f'{namespace}:') prop_name = prop_name.lstrip(f'{namespace}:')
res.append(Property(key=prop_name, value=prop_value, source=prop_source, namespace=namespace)) res.append(Property(key=prop_name, value=prop_value, source=property_source, namespace=namespace))
else: else:
res.append(Property(key=prop_name, value=prop_value, source=prop_source, namespace=None)) res.append(Property(key=prop_name, value=prop_value, source=property_source, namespace=None))
return res return res

@ -6,7 +6,7 @@ CLI-based implementation of ZPOOL.
import logging import logging
import shutil import shutil
from typing import Any, Dict, NamedTuple, Optional from typing import Any, Dict, Optional
from .types import ZPoolHealth from .types import ZPoolHealth
from .zpool import ZPool from .zpool import ZPool

@ -32,6 +32,7 @@ class TestDatasetType:
DatasetType.from_string(None) DatasetType.from_string(None)
assert 'only string' in str(excinfo.value) assert 'only string' in str(excinfo.value)
class TestPropertySource: class TestPropertySource:
@pytest.mark.parametrize('string,value', [('default', PropertySource.DEFAULT), ('DeFAULT', PropertySource.DEFAULT), ('inheriteD', PropertySource.INHERITED), ('inherited', PropertySource.INHERITED), ('TEMPORARY', PropertySource.TEMPORARY), ('temporary', PropertySource.TEMPORARY), ('rEcEiVeD', PropertySource.RECEIVED), ('received', PropertySource.RECEIVED), ('None', PropertySource.NONE), ('none', PropertySource.NONE)]) @pytest.mark.parametrize('string,value', [('default', PropertySource.DEFAULT), ('DeFAULT', PropertySource.DEFAULT), ('inheriteD', PropertySource.INHERITED), ('inherited', PropertySource.INHERITED), ('TEMPORARY', PropertySource.TEMPORARY), ('temporary', PropertySource.TEMPORARY), ('rEcEiVeD', PropertySource.RECEIVED), ('received', PropertySource.RECEIVED), ('None', PropertySource.NONE), ('none', PropertySource.NONE)])

@ -238,6 +238,7 @@ class TestMetadataPropertyName:
validate_metadata_property_name('a' * 1024) validate_metadata_property_name('a' * 1024)
assert 'length >' in str(excinfo.value) assert 'length >' in str(excinfo.value)
class TestPropertyValue: class TestPropertyValue:
''' '''
Tests the function ``validate_property_value``. Tests the function ``validate_property_value``.

Loading…
Cancel
Save